最後更新時間於: 2021-10-01
Google Cloud Platform(GCP)免費計畫可能你沒有聽過,不過不重要,它主要是提供給大家90 天的免費試用期,並提供價值 $300 美元的抵免額,也就是說能免費架設一個90天的高速網站來起步,非常適合新手去體驗一下。詳細的計畫資料也不多重複了,可以到 GCP的介紹裡面看看!傳送門

很多新手都害怕使用 GCP主要原因都是擔心試用期過後會自動繼續扣費!站長也試用過很多雲端平台,唯一google cloud是會主動幫你在試用期過後會自動停掉所有你在試用期間的用過的東西,所以是完全不怕哪一個東西沒有關掉而有無故收費的情況出現,可以有一個盡情試用的環境給你。讓新手沒有玩過用虛擬機建wordpress的人可以嘗試一下新鮮事物!!
是次會使用 GCP + wordops 來簡單架設一個相對較快的wordress!想一起學習用虛擬機建設快速wordpress方法的話,就繼續閱讀下去吧~
架設高速wordpress前置準備
- 信用卡/預付卡x1
- 域名x1
在繼續往下閱讀前,如果你沒有信用卡/預付卡的話,那麼就不用繼續閱讀下去,主要原因是無法完成註冊GCP
註冊google cloud Platform

GCP試用連結:傳送門 ,一般進入連結後會看到免費試用的按鈕

簡單填寫資料就能完成申請,過程中需要一張信用卡/預付卡,同時完成申請後,google會扣掉你1美金做測試你的信用卡/預付卡真實性,通常是即時會退回1美金給你的!
架設高速wordpress
這次的wordpress會用上wordops的自動化程序來完成這次安裝,選用wordops主要原因是它整體夠輕巧,只需要512MB的主機上都能運作暢順,實際運行上在一個日流量約5000訪客上也沒有甚麼大問題~所以非常推薦使用!

當你完成GCP註冊後,可以看到上面的畫面,從最左上角的三→運算 → VM執行個體,開始建立我們的第一個虛擬機!

點進VM執行個體後,點擊建立執行個體進行詳細配置你的虛擬機



進入虛擬機詳細配置後,基本上要注意的是區域的選擇,儘量選擇和你網站本身訪客主要來源的地區,機器設定選擇N1和1VCPU,3.75GB就足夠了!
開機磁碟方面要選擇Ubuntu20.04 lts版本以及30GB的SSD,已經足夠應付多圖片的網站
wordops簡單安裝教學

完成虛擬機的建立後,可以從 連線→SSH → 在瀏覽器視窗中開啟黑視窗

進入黑視窗會大概呈現上面的樣子
進行虛擬機安裝wordops
接著下來會給大家最簡化安裝程序,只安裝需要的東西,同時也會提供代碼方便複製貼上, ,更多的代碼可以參考官方資料 !
wordops一鍵自動安裝程式
安裝程式的script,會自動幫你安裝需要的依賴項目
wget -qO wo wops.cc && sudo bash wo
Welcome to WordOps install/update script v3.13.2
Installing wo dependencies [OK]
Installing WordOps [OK]
Running post-install steps [OK]
WordOps (wo) require an username & and an email address to configure Git (used to save server configurations)
Your informations will ONLY be stored locally
Enter your name:
Enter your email:[email protected]
Synchronizing wo database, please wait...
WordOps (wo) installed successfully
To enable bash-completion, just use the command:
bash -l
To install WordOps recommended stacks, you can use the command:
wo stack install
To create a first WordPress site, you can use the command:
wo site create site.tld --wp
WordOps Documentation : https://docs.wordops.net
WordOps Community Forum : https://community.wordops.net
WordOps Community Chat : https://chat.wordops.net
Give WordOps a GitHub star : https://github.com/WordOps/WordOps/
啟用 bash_completion和建立sudo wo的別名
主要是簡單化讓你wordops幫你完成大部代碼以及增加你的方便性
source /etc/bash_completion.d/wo_auto.rc
echo -e "alias wo='sudo -E wo'" >> $HOME/.bashrc
source $HOME/.bashrc
安裝堆棧 stacks
安裝堆棧 stacks能幫你做一個可視化的後台資訊監控,比如看到目前虛擬機狀態、訪問wordpress文件和數據庫等等,完成堆棧 stacks時會暫時訪問不了後台的,主要是沒有完成防火牆設定
wo stack install
WordOps (wo) require an username & and an email address to configure Git (used to save server configurations)
Your informations will ONLY be stored locally
Enter your name:
Enter your email: [email protected]
WP-CLI is already installed
Start : wo-kernel [OK]
Adding repository for MySQL, please wait...
Adding repository for NGINX, please wait...
Adding repository for PHP, please wait...
Updating apt-cache [OK]
Installing APT packages [OK]
Applying Nginx configuration templates
Testing Nginx configuration [OK]
Restarting Nginx [OK]
Testing Nginx configuration [OK]
Restarting Nginx [OK]
Configuring php7.3-fpm
Restarting php7.3-fpm [OK]
Tuning MySQL configuration [OK]
Restarting mysql [OK]
Restarting fail2ban [OK]
Configuring Fail2Ban
Configuring Sendmail [OK]
Downloading PHPMyAdmin [Done]
Downloading phpRedisAdmin [Done]
Downloading Composer [Done]
Downloading Adminer [Done]
Downloading Adminer theme [Done]
Downloading MySQLTuner [Done]
Downloading Netdata [Done]
Downloading WordOps Dashboard [Done]
Downloading eXtplorer [Done]
Downloading cheat.sh [Done]
Downloading bash_completion [Done]
Downloading clean.php [Done]
Downloading opcache.php [Done]
Downloading Opgui [Done]
Downloading OCP.php [Done]
Downloading Webgrind [Done]
Downloading pt-query-advisor [Done]
Downloading Anemometer [Done]
Installing composer [OK]
Installing Netdata [OK]
Restarting netdata [OK]
Configuring packages [OK]
HTTP Auth User Name: WordOps
HTTP Auth Password : xxxxxxxxxxxxxxxxxxxxxxxxxx
WordOps backend is available on https://xxx.xxx.xx:22222
Successfully installed packages
設定安全防火牆
wo stack install --ufw
建立網站和目錄和檔案權限設定
wo site create xxxx.com --wpredis
sudo find /var/www/xxxxx.com/htdocs/ -type d -exec chmod 2775 {} \;
sudo find /var/www/xxxxx.com/htdocs/ -type f -exec chmod 664 {} \;
當你看到這邊時,操作誤的話,已經就可以完成建立你的第一個高速wordpress網站,但還差最後一步把防火牆打開就正式完成!
開啟防火牆和獨立ip


以上的動作是保留目前的伺服器ip,讓它成為獨立的ip,獨立ip能提升小部分的網站速度,對網站未來seo有相當不錯的加分


從建立防火牆裡面按照上圖填寫一個輸入方向的防火牆,目標標記是可以按你喜好填寫的,但請記住填寫的內容

上圖是輸入方向,同樣方法填寫並且建立


回到執行個體頁面,從虛擬機名稱中進入編輯該虛擬的,並且在網路標記填寫上面防火牆設定中填寫的目標標記的內容!
網站速度測試

來到最後完成階段了,只要從xxx.com或者 XXX.com/wp-admin就能進行wordpress最後網站資訊設定


本站也是透過該方式進行建立的wordpress,從google pagespeed 中測試可以看到都達幾乎滿分狀態
(測試時間為2021/10/1)
總結:
這次的文章主要給一些想利用虛擬機建立高速wordpress的朋友同時也是幫自己記錄建立高速wordpress的方法,在這次的研究怎麼使用gcp過程中學到很多知識同時也發現一個可循環GCP額度的方式,讓自己偷偷可以暫時省下不少主機的費用,日後有機會會寫下來怎麼操作!!
常見問題:
google cloud Platform會無故收費的嗎?
不會,一般過了90天/額度用完就會很人性化自動幫你停掉所有東西,絕對不會多收費的
GCP額度過期後資料還能拿的回來嗎?
您的 Cloud Billing 帳戶會進入 30 天的寬限期,您可以在這段期間內復原在試用期間內儲存至任何 Google Cloud 服務的資源和資料。