WordOps 快速建立高效能 WordPress 和管理教學 - MIS 腳印
MIS 腳印 logo

MIS 腳印

記錄 IT 學習的軌跡

WordOps 快速建立高效能 WordPress 和管理教學

WordOps 能快速及簡化 WordPress 網站的安裝流程,並自動配置網站伺服器 Nginx 最佳化,帶有 fastcgi_cache 或 Redis 等快取的 WordPress 網站,以及使用 DNS API 方式來自動申請並延續 Let's Encrypt 免費 Wildcard 萬用字元憑證,且還能透過 WordOps 網頁後台即時監控伺服器效能。

WordPress.ORG

作業系統與硬體要求

請參考 WordOps 官網 Prerequisites - WordOps Documentation

安裝

一鍵自動安裝程式 script,它會在設置 WordOps 之前安裝必需的依賴項目 (詳細說明可參考 Installation - WordOps Documentation):

wget -qO wo wops.cc && sudo bash wo
[sudo] password for jacky:

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: fooxxxrk
Enter your email: fooxxxrk.xxxx@gmail.com
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

要啟用 WordOps 命令自動完成功能,請在安裝 WordOps 之後執行以下指令:

source /etc/bash_completion.d/wo_auto.rc

為 sudo wo 建立別名

如果希望能夠以非 root 直接執行 wo 指令,可增加 bash 別名,來自動在 wo 指令前自動添加 sudo 指令:

echo -e "alias wo='sudo -E wo'" >> $HOME/.bashrc

要立即生效請執行:

source $HOME/.bashrc

安裝堆棧 stacks (可選)

可以在新建一個網站之前使用以下指令安裝 WordOps 所有 stacks,也可以直接新建一個網站,然後 WordOps 在安裝所需的 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: footmark
Enter your email: footmark.info@gmail.com
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 : xxxxrMTs8PxxxxFuPSxxxx
WordOps backend is available on https://61.216.xxx.xx:22222 or https://61-216-xxx-xx.HINET-IP.hinet.net:22222
Successfully installed packages

WordOps 後台

開啟瀏覽器輸入上述 WordOps backend 後台 IP or 網址,輸入帳、密即可登入:

WordOps 後台登入
WordOps 後台登入
WordOps 後台監控
WordOps 後台監控

修改 WordOps 後台帳密

在上述 stack 安裝 Nginx 之後,WordOps 將會顯示登入 WordOps 後台的 HTTP Auth 使用者帳號和密碼。忘記保存了嗎?不用擔心,您可隨時使用以下指令更改:

wo secure --auth
Provide HTTP authentication user name [footmark] :jxxxk
Provide HTTP authentication password [BtDvMUm1rjnErb3fd4TO2nY9] :

啟用 WordOps 預設 UFW 防火牆

WordOps UFW 需允許的 port 可參考 Prerequisites - WordOps Documentation

如尚未在伺服器配置防火牆,則可執行以下指令來自動配置 WordOps 最少規則的 UFW 規則:

wo stack install --ufw

自行手動設定 UFW 規則方式可參考 Ubuntu Server 20.04.1 預設 UFW 防火牆 Firewall 設定規則詳解和教學 - MIS 腳印

建立 WordPress 網站

預設語系設定

設定 WordPress 預設使用的語系為中文 (繁體) zh-TW (設定時必須將 - 改為 _ 下底線) :

sudo vim ~/.wp-cli/config.yml
core download:
    locale: zh_TW

一般的網站

使用帶有選項 --wp 來建立 WordPress 網站 :

wo site create test.footmark.com.tw --wp

帶有 Nginx 快取 fastcgi_cache 的網站

使用帶有選項 --wpfc 來建立帶有 Nginx 快取 fastcgi_cache 的 WordPress 網站:

wo site create test.footmark.com.tw --wpfc
Running pre-update checks       [OK]
Setting up NGINX configuration  [Done]
Setting up webroot              [Done]
Downloading WordPress           [Done]
Setting up database             [Done]
Configuring WordPress           [OK]
Installing WordPress            [OK]
Installing plugin nginx-helper  [OK]
Setting plugin nginx-helper     [OK]
Testing Nginx configuration     [OK]
Reloading Nginx                 [OK]
WordPress admin user : foxxxark
WordPress admin password : xxxpTFrDEkIGxxxHNf5qLxxx
Nginx-Helper configuration :    http://test.footmark.com.tw/wp-admin/options-general.php?page=nginx
Successfully created site http://test.footmark.com.tw

帶有 Redis 快取的網站

使用帶有選項 --wpredis 來建立帶有 Redis 快取的 WordPress 網站:

wo site create test.footmark.com.tw --wpredis

目錄和檔案權限設定

遞迴更改網站目錄下,所有目錄的權限設定:

sudo find /var/www/test.footmark.com.tw/htdocs/ -type d -exec chmod 2775 {} \;

遞迴更改網站目錄下,所有檔案的權限設定:

sudo find /var/www/test.footmark.com.tw/htdocs/ -type f -exec chmod 664 {} \;

刪除網站

wo site delete test.footmark.com.tw
Are you sure, you want to delete database [y/N]: y
Deleting Database, test_footmark_com_tw_KXlSAtDM, user testfootmarkZR3N
Deleted Database successfully.
Are you sure, you want to delete webroot [y/N]: y
Deleting Webroot, /var/www/test.footmark.com.tw
Deleted webroot successfully
Testing Nginx configuration     [OK]
Reloading Nginx                 [OK]
Removing Acme configuration
Setting back default certificate for WordOps backend
Deleted site test.footmark.com.tw

Let's Encrypt (申請 HTTPS 憑證)

使用 DNS API 方式來申請 Let's Encrypt 免費 Wildcard 萬用字元憑證,以 GoDaddy 為例申請 DNS API 方式請參考 Let's Encrypt 免費 Wildcard 萬用字元憑證 SSL/TLS for CentOS 7 - MIS 腳印

設定 GoDaddy 申請好的 DNS API :

export GD_Key="xxxxxxpTEP3_5xxxxxxdn3Tdwv8Pxxxxxx"
export GD_Secret="xxxxxxmvLxQ3ZwuWxxxxxx"

以 GoDaddy DNS API 將目前已存在網站,更新 Wildcard 萬用字元憑證 SSL/TLS:

wo site update test.footmark.com.tw --wp --letsencrypt=wildcard --dns=dns_gd
Certificate type : wildcard
Validation mode : DNS mode with dns_gd
Issuing SSL cert with acme.sh   [OK]
Deploying SSL cert              [OK]
Securing WordOps backend with current cert
Adding HTTPS redirection        [OK]
Updating site url with https    [OK]
Testing Nginx configuration     [OK]
Reloading Nginx                 [OK]
Congratulations! Successfully Configured SSL on https://test.footmark.com.tw
Your cert will expire within 89 days.

其它

查看已建立的所有網站

wo site list
test.footmark.com.tw
footmark.com.tw

查看網站資訊

wo site info footmark.com.tw
Information about footmark.com.tw (domain):


Nginx configuration      wp wpfc (enabled)
PHP Version              7.3

SSL                      enabled
SSL PROVIDER             Lets Encrypt
SSL EXPIRY DATE          89

access_log               /var/www/footmark.com.tw/logs/access.log
error_log                /var/www/footmark.com.tw/logs/error.log
Webroot                  /var/www/footmark.com.tw

DB_NAME                  foxxxark_com_tw_xxxxxJ02
DB_USER                  foxxxarkcxxxxx5f
DB_PASS                  xxxxxxwP3sxxxxxTujCxxxxx

NGINX 設定檔

共用客製 NGINX 設定檔

編輯共用客製 NGINX 設定檔 for PHP 7.3 版本:

vim /etc/nginx/common/php73.conf.custom 
# PHP NGINX CONFIGURATION - WordOps 3.13.2
# DO NOT MODIFY, ALL CHANGES WILL BE LOST AFTER AN WordOps (wo) UPDATE
location / { 
  try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
  try_files $uri =404;
  include fastcgi_params;
  fastcgi_pass php73;
}

網站獨立 NGINX

編輯 NGINX 設定檔:

wo site edit footmark.com.tw
server {
    server_name footmark.com.tw www.footmark.com.tw;

    access_log /var/log/nginx/footmark.com.tw.access.log rt_cache;
    error_log /var/log/nginx/footmark.com.tw.error.log;

    root /var/www/footmark.com.tw/htdocs;

    index index.php index.html index.htm;

    include common/wpfc-php73.conf;
    
    include common/wpcommon-php73.conf;
    include common/locations-wo.conf;
    include /var/www/footmark.com.tw/conf/nginx/*.conf;
}

參考

WordOps - High performance WordPress stack with a few keystrokes

發表迴響