Ruofan Wei
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
      • No invitee
    • Publish Note

      Publish Note

      Everyone on the web can find and read all notes of this public team.
      Once published, notes can be searched and viewed by anyone online.
      See published notes
      Please check the box to agree to the Community Guidelines.
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
No invitee
Publish Note

Publish Note

Everyone on the web can find and read all notes of this public team.
Once published, notes can be searched and viewed by anyone online.
See published notes
Please check the box to agree to the Community Guidelines.
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 網站部署 ###### tags: `Tag(網站部署)` >[參考資料-部屬 AWS EC2 雲端主機 + LAMP Server + phpMyAdmin + CloudFlare](https://medium.com/@hugh_Program_learning_diary_Js/%E9%83%A8%E5%B1%AC-aws-ec2-%E9%9B%B2%E7%AB%AF%E4%B8%BB%E6%A9%9F-lamp-server-phpmyadmin-cloudflare-43871cd5dd01) >[參考資料-部署 AWS EC2 遠端主機 + Ubuntu LAMP 環境 + phpmyadmin](https://github.com/Lidemy/mentor-program-2nd-yuchun33/issues/15) >[參考資料-一小時完成 VPS (Virtual Private Server) 部署 ](https://github.com/Lidemy/mentor-program-2nd-futianshen/issues/21) ###### `使用的主機` - [aws](https://aws.amazon.com/tw/console/) #### <font color="#b590ca">部署前可以先選地區,亞洲區速度會比較快</font> :::warning ![](https://i.imgur.com/FSIMEoN.png) ::: #### <font color="#b590ca">選擇啟動虛擬機器開始部署</font> :::warning ![](https://i.imgur.com/tvyUzyv.png) ::: #### <font color="#b590ca">AMI 選擇 Ubuntu</font> :::warning ![](https://i.imgur.com/Sn1vOPB.png) ::: #### <font color="#b590ca">instance type 選擇不同主機的等級,選擇免費的版本接著按下 next 做其他的設定</font> :::warning ![](https://i.imgur.com/UqunEea.png) ::: #### <font color="#b590ca">instance details 網路相關設定,直接選擇next不做任何更動</font> :::warning ![](https://i.imgur.com/0gJmGe5.png) ::: #### <font color="#b590ca">Add storage主機硬碟要多大,直接選擇next不做任何更動</font> :::warning ![](https://i.imgur.com/E4kuLI4.png) ::: #### <font color="#b590ca">Add tags 方便管理主機,直接選擇next不做任何更動</font> :::warning ![](https://i.imgur.com/L79IR7m.png) ::: #### <font color="#b590ca">aws上的防火牆,這邊新增http 80port、mysql 3306port、https 443 也可以連進主機,接著按review and launch</font> :::warning ![](https://i.imgur.com/sVnaSwc.png) ::: #### <font color="#b590ca">按下launch後會出現需要產生一組密碼來連線主機,下載完密碼後按下launch instance</font> >這組密碼在設定filezilla時會需要用到 :::warning ![](https://i.imgur.com/XLscpQs.png) ::: #### <font color="#b590ca">成功running就可以打開iterm2</font> :::warning ![](https://i.imgur.com/3GmMR88.png) ::: #### <font color="#b590ca">打開iterm2後如果直接用ssh 加上key連接主機會跑出 key的權限太高的問題</font> :::warning ![](https://i.imgur.com/GLgfEBE.png) ::: :::warning ![](https://i.imgur.com/tLkLazk.png) ::: #### <font color="#b590ca">可以使用aws網站上connect建議的設定,先使用chmod 400 加上key降低權限,再用ssh連線</font> :::warning ![](https://i.imgur.com/dgo7XLX.png) ::: #### <font color="#b590ca">使用指令top可以看到即時更新的主機資訊,按q可以離開</font> :::warning ![](https://i.imgur.com/aiFXaoE.png) ::: #### <font color="#b590ca">接著先更新ubuntu系統,sudo是指要用管理員的身份去執行,apt是指在ubuntu上面管理套件軟體</font> :::warning ![](https://i.imgur.com/JQDymAR.png) ::: #### <font color="#ad9d9d">使用 `sudo apt install tasksel` 安裝tasksel</font> #### <font color="#ad9d9d">tasksel是一個軟體包(輔助工具),協助安裝其他軟體(像是lamp-server)</font> :::warning ![](https://i.imgur.com/duY9s72.png) ::: #### <font color="#b590ca">把Public IPv4 address貼到chrome,網頁成功顯示代表apache的server有架起來</font> :::warning ![](https://i.imgur.com/orChMvW.png) ::: ##### <font color="#b590ca">用指令`sudo mysql -u root mysql`登入mysql(用輸入者身份)</font> ##### <font color="#b590ca">讓root可以登入phpmyadmin `UPDATE user SET plugin='mysql_native_password' WHERE User='root';` </font> ##### <font color="#b590ca">更新權限 `FLUSH PRIVILEGES;`</font> ##### <font color="#b590ca">離開 `exit;`</font> :::warning ![](https://i.imgur.com/B7Jorp1.png) ::: #### <font color="#b590ca">設root密碼</font> :::warning ![](https://i.imgur.com/3VaPRVv.png) ::: #### <font color="#b590ca">登入phpmyadmin後,更新使用者root的權限,就可以從自己的電腦透過別的軟體(任意主機)連到遠端主機</font> :::warning ![](https://i.imgur.com/0CLzxgI.png) ::: #### <font color="#b590ca">測試php有沒有跑起來</font> >##### <font color="#b590ca">使用`sudo chown ubuntu /var/www/html`讓ubuntu可以有權限更改檔案</font> :::warning ![](https://i.imgur.com/w3ATFyq.png) ::: #### <font color="#b590ca">接著可以把local的資料庫匯出資料,遠端的資料庫匯入資料</font> >#### <font color="#b590ca">設定filezilla</font> :::warning ![](https://i.imgur.com/zErMBue.png) ::: >#### <font color="#b590ca">設定完成後找到正確的檔案放置的位置再新增檔案</font> :::warning ![](https://i.imgur.com/heUvZUM.png) ::: :::warning ![](https://i.imgur.com/bIm3P8W.png) ::: #### <font color="#b590ca">設定完gandi後就完成拉</font> :::warning ![](https://i.imgur.com/jW73eGx.png) ::: --- ## 什麼是 DNS? >[什麼是 DNS?](https://aws.amazon.com/tw/route53/what-is-dns/) 是==網域名稱系統==,將可讀取的網域名稱 (例如,`www.amazon.com`) 轉換為機器可讀取的 IP 地址 (例如,`192.0.2.44`)。 ## 什麼是資料庫的 lock?為什麼需要 lock? >模擬一個在購物網站搶購的情況。如果有很多人一起去搶購,==同時執行怎麼辦?== 這種情況就叫做 `race condition`,意思就是==有兩個或以上同時在存取資個資料的時候會發生的問題-超賣。== 這種時候,需要加上一個 `lock`,而這個 `lock` ==只有 `transaction` 可以使用。== ```c * 只需要在指令後面加上 for update 。 就可以鎖定資料,讓資料後續接收資料之後,才可以繼續接收其他資料。 * 這時候只能接收一筆資料。但這樣做會有效能上面的耗損。 * 假如有指定 where id = 1 就會只把那個 row 給鎖定起來。 但如果沒有的話,就會把整個 table 被鎖定。 ``` ```c $conn->autocommit(FALSE); $conn->begin_transaction(); $conn->query("SELECT amount from products where id = 1 for update"); $conn->commit(); ``` ## NoSQL 跟 SQL 的差別在哪裡? >[SQL 與 NoSQL](https://ithelp.ithome.com.tw/articles/10187443) ==SQL 是一個拿來查詢資料庫的語言==,並不是一個資料庫系統,MySQL 才是。 ```c * 任何一種以 SQL 為基礎的資料庫系統,都有差不多的特性 * 例如: 必須事先定義好 Schema,可以想成是資料庫的規格書。 就是資料庫裡面要有哪些欄位、每一個欄位的資料型態是什麼。 ``` ##### `NoSQL特性` ```cs 1. 沒有 Schema,可以想像成存 JSON 資料進 DB (Schema 就是結構,也就是 table 看起來的模樣,有 id 名稱 型態等資訊) 好處是比較彈性,可是相對的在查詢資料的時候速度也會比較慢一點。 2. 用 key-value 來存 3. 不支援 JOIN 4. 通常用來存一些結構不固定的資料(log 之類的) ``` >如果把資料存在 NoSQL 的資料庫裡面,可能就會長這樣: ```j { id: 1, author: 'huli', content: '大家好', create_time: 12345, comments: [ { id: 1, content: 'comment 1', create_time: ... }, { id: 2, content: 'comment2', create_time: ... } ] } ``` NoSQL 最適合的一點是 ==搜集數據。== ```c * 例如說現在很多手機 App 其實會偷偷搜集你的資料傳回去 做一些數據分析之類的。 * 可能會搜集:手機廠牌、型號、作業系統版本、安裝過的 App 等等的。 ``` SQL 跟 NoSQL 並不是互斥的概念,==可以在你的系統裡面用 SQL 類的資料庫系統儲存文章、評論,同時也用 NoSQL 類的資料庫來搜集使用者資訊。== ## 資料庫的 ACID 是什麼? >[SQL 大小事](https://medium.com/@totoroLiu/%E8%B3%87%E6%96%99%E5%BA%AB-acid-bb87324035a8) ```c * 在資料庫的交易中,為確保交易(Transaction)是正確可靠的,所以必須具備四個特性 1. Atomicity (原子性) * 資料操作不能只有部分完成。 一次的 transaction 只能有兩種結果:成功或失敗 2. Consistency (一致性) * transaction 完成前後,資料都必須永遠符合 schema 的規範 保持資料與資料庫的一致性 3. Isolation (隔離性) * 資料庫允許多個 transactions 同時對其資料進行操作 但也同時確保這些 transaction 的交叉執行 不會導致數據的不一致 4. Durability (持續性) * transaction 完成後,對資料的操作就是永久的 即便系統故障也不會丟失 ``` ## 什麼是資料庫的 View 以及使用時機 >[View 檢視表、視圖 (SQL View)](https://www.fooish.com/sql/view.html) 又稱==檢視表==,是一個虛擬的資料表。 ```c * 優點:隱藏/過濾原始資料,並簡化資料查詢。 加強資料庫的安全性,View 可以將實體資料表結構隱藏起來, 同時限制使用者只可以檢視及使用哪些資料表欄位。 ``` ###### `建立 View` ```javascript CREATE VIEW view_name [(column_list)] AS SELECT column_name(s) FROM table_name WHERE condition; // CREATE VIEW 表格名稱 AS 欲建立表格的SQL指令 ``` ## 什麼是 Stored procedure 以及如何使用 >[資料庫補充 View、Stored Procedure 與 Trigger](https://medium.com/@hugh_Program_learning_diary_Js/%E5%BE%8C%E7%AB%AF%E5%9F%BA%E7%A4%8E-%E8%B3%87%E6%96%99%E5%BA%AB%E8%A3%9C%E5%85%85-view-stored-procedure-%E8%88%87-trigger-8dbcbf5946a9) 就像是 ==sql 的 function。== 語法: ```sql delimiter // CREATE PRECEDURE 函式名稱(變數 變數型態) BEGIN 執行內容; END // delimiter; ``` :::warning ![](https://i.imgur.com/WC5g8Dz.png) ::: >==預存程序是專門寫== function 的地方,不需要使用delimiter :::warning ![](https://i.imgur.com/IleN9ri.png) ::: 使用的時候 - 加 ==`CALL`== 才可以呼叫: ```sql CALL 函式名稱(引數) ``` 因為是把 function 寫在資料庫上面,所以需要 ==debug 就必須要打開資料庫==才可以看到長什麼樣子,就會造成許多麻煩 ## 資料庫的 Trigger 以及使用時機 ==儲存一些變動資訊==,也就是 log 。 ```spl delimiter // CREATE TRIGGER 名稱 BEFORE UPDATE FROM table名稱 FOR EACH ROW BEGIN 要做什麼; END // delimiter; ``` :::warning ![](https://i.imgur.com/hMDBibk.png) ::: >==預存程序是專門寫== function 的地方,不需要使用delimiter :::warning ![](https://i.imgur.com/IleN9ri.png) ::: 往後==只要變動資料,就會被記錄下來。== --- ## 讓PHP顯示錯誤訊息 >[顯示PHP錯誤訊息 加速偵錯(Debug)效率](https://magiclen.org/php-debug/) ==設定php.ini,讓PHP顯示出錯誤訊息==,加速偵錯(Debug)的效率。 ###### 到`/etc資料夾`後,一層一層接著找到php.ini :::warning ![](https://i.imgur.com/TDbslg1.png) ::: ##### 使用`sudo vim php.ini`更新 ==`display_errors`為`on`== ##### 接著使用`sudo service apache2 restart`==重啟Apache== #### <font color="#b590ca">就能直接看到bug出現在哪一行了!</font>

Import from clipboard

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template is not available.
Upgrade
All
  • All
  • Team
No template found.

Create custom template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

How to use Slide mode

API Docs

Edit in VSCode

Install browser extension

Get in Touch

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Upgrade to Prime Plan

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

No updates to save
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Upgrade

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Upgrade

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully