Wordpress 架設流程

BUBU 因為要幫老婆大人的工作室建立一個官方的網頁及購物中心,因此選擇最熱門的 WordPree CRM 套件來設架

架設環境為


CentOS 7、Nginx:1.15、OpensSSL:1.1.1b、MariaDB:10.4、PHP:7.3

Nginx 安裝及設定


請參考之前架設的設定啟用Nginx 支援到 OpenSSL TLS1.3 安全協定

MariaDB 安裝及設定


  • 首先新增加 MariaDB.repo 官方載點
新增加MariaDB安裝檔
vim /etc/yum.repos.d/MariaDB.repo

再填入內容為以下
# MariaDB 10.4 CentOS repository list - created 2019-11-05 06:33 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
增加完畢後在下命令安裝

yum install MariaDB-server MariaDB-client -y
  • 資料庫安裝及設定
systemctl enable mariadb ; systemctl start mariadb   # 啟動資料庫服
mysql_secure_installation   # 設定資料庫的root密碼

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n]
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n]
New password:                   #設定 root 密碼
Re-enter new password:          #確認 root 密碼
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

mysql -u root -p   # 登入資料庫裡設定資表及權限

CREATE DATABASE IF NOT EXISTS wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; #在資料庫裡新增wordpress表單
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION; #密碼請自己輸入好記錄的密碼
FLUSH PRIVILEGES;
exit

PHP 7.3 安裝及設定

  • 先安裝額外的套件及載點
yum install -y epel-release yum-utils
  • 因內鍵預設版本是 PHP 5.4 因此本版官方已不在維護,建議直接安裝當時官方所提供主要版本,現在安裝版本是 PHP 7.3
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum-config-manager --disable remi-php54
yum-config-manager --enable remi-php73
  • 安裝 PHP 套件
yum install -y php php-mysqlnd php-pdo php-xml php-pear php-devel php-mbstring re2c gcc-c++ gcc \
php-fpm php-mysql php-gd php-cli php-json php-opcache php-curl php-ldap php-odbc php-xmlrpc php-soap \
curl curl-devel php-intl php-zip
  • 安裝好 PHP 要去修改 「vim /etc/php.ini」 設定檔
修改前
;cgi.fix_pathinfo=1
修改後
cgi.fix_pathinfo=0
修改時區
[Date]
修改前
;date.timezone = 
修改後
date.timezone = Asia/Taipei
修改資料上傳限制
; 上傳檔案大小上限(單一檔案大小)
upload_max_filesize = 50M 

; POST 大小上限(所有檔案大小加總)
post_max_size = 200M

; 記憶體用量上限
memory_limit = 512M

;Script執行時間上限(單位:秒)
max_execution_time = 600

; Script處理資料時間上限(單位:秒)
max_input_time = 600

; Socket無回應斷線時間(單位:秒)
default_socket_timeout = 600

; 調整 PHP 的 POST 數量限制
max_input_vars = 1500

存檔
:wq
  • 設定「php-fpm」「vim /etc/php-fpm.d/www.conf
由誰使用此服務
; RPM: apache user chosen to provide access to the same directories as httpd
;user = apache
user = nginx
; RPM: Keep a group allowed to write in log dir.
;group = apache
group =nginx

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
;                 mode is set to 0660
listen.owner = nobody
listen.group = nobody
;listen.mode = 0660

修改好存檔
:wq
  • 重啟及開機自動啟動 php-fpm 服務
systemctl restart php-fpm ; systemctl enable php-fpm

設定 Nginx 服務設定檔


設定「vim /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
#
events {
    worker_connections 1024;
}
#
http {
    include /etc/nginx/mime.types;
#gzip  on;
    include /etc/nginx/conf.d/*.conf;
    default_type application/octet-stream;
    log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log  main;
    sendfile on;
#tcp_nopush     on;
    keepalive_timeout 65;
# 以下是反代理取得真實 IP    
# Restoring the original visitor IP for your web application
    set_real_ip_from 內網 IP ;
    set_real_ip_from 公網 IP 指的是自己目前當下的 IP;
    set_real_ip_from 127.0.0.1;
# use any of the following two
# real_ip_header CF-Connecting-IP;
    real_ip_header X-Forwarded-For;
}
  • 設定「vim /etc/nginx/conf.d/XXX.conf」
server {
# 這個主機的 Port
    listen 80;
# 這個主機的名稱
    server_name 主機IP或網址;
    rewrite ^(.*)$ https://${server_name}$1 permanent;
}
#
server {
# 使用 https 和 http/2 協定
    listen 443 ssl http2;
# 上述的 IPv6 方式
    listen [::]:443 ssl http2;
    server_name 主機IP或網址;
    root /usr/share/nginx/html/wordpress;
# 
# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
#
# SSL 憑證證書路徑
    ssl_certificate /etc/nginx/ssl/cert.pem;
# 私鑰路徑
    ssl_certificate_key /etc/nginx/ssl/key.pem;
# 緩存有效期
    ssl_session_timeout 1d;
# 緩存憑證類型和大小
    ssl_session_cache shared:SSL:50m;
#
# intermediate configuration. tweak to your needs.
#
# 使用的加密協定
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
# 加密演算法,越前面的優先級越高
    ssl_ciphers 'TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5';
# 交握過程使用 Server 的首選加演算法,這裡使用 Client 為首選
    ssl_prefer_server_ciphers on;
#
# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
#
# 增加 http header
    add_header Strict-Transport-Security max-age=63072000;
#
    access_log /var/log/nginx/plf_access.log;
    error_log /var/log/nginx/plf_error.log;
#
    client_max_body_size 1G;
    fastcgi_buffers 64 4K;
#
# html 檔
    location / {
# 使用「瀏覽器」瀏覽根目錄時,未指定檔名時預設使用的檔案
        index index.php index.html index.htm;
        autoindex on;
        try_files $uri $uri/ /index.php?$args;
    }
    location = /50x.html {
        root /usr/share/nginx/html;
    }
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
# php 檔
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        try_files $uri =404;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_intercept_errors on;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
    }
#
    location ~* \.(?:ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        expires 30d;
        log_not_found off;
    }
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
    location ~ /\.ht {
        deny all;
    }
# 發生 404 指定導向哪個網頁
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
#
    error_page 500 502 503 504  /50x.html;
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
# location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}
}
  • 重啟 nginx 服務
systemctl restart nginx

開始安裝 wordpree


  • 到官方網站下載最新版本 官方 當時下載的版本為5.1.1,下載好之後將檔案放置到 web 服務下的目錄,並且重新設定該目錄的權限
chown -R nginx:nginx wordpress/

設定完之後就恭喜您可以開始使用 wordpree 服務來經營個人、工作室或企業的官方網站了




參考相關網頁