====== CentOS7 安裝 WordPress 5 程序 ====== * CentOS 7.6.1810 (Core) * Nginx 1.12.2 * MariaDB 10.3.12 * PHP 7.3.1 ===== 安裝 Nginx / MariaDB / PHP 7 ===== * EPEL yum install -y epel-release yum-utils * Remi 關閉 5.4 啟用 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 * nginx vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 yum install -y nginx * php-fpm yum install -y php-fpm php * mariadb-server vi /etc/yum.repos.d/MariaDB.repo # MariaDB 10.3 CentOS repository list - created 2019-01-25 13:04 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 yum install -y MariaDB-server ===== 設定與驗證 nginx+php-fpm / mariadb ===== * Firewall 開啟 http / https firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload * 設定 nginx 開機啟動 systemctl restart nginx systemctl enable nginx * 設定主網站頁目錄 vi /etc/nginx/conf.d/default.conf server { listen 80; server_name localhost; gzip on; gzip_comp_level 5; gzip_min_length 256; gzip_proxied any; gzip_vary on; gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; # text/html is always compressed by gzip module location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ { expires 7d; } charset utf-8; access_log /var/log/nginx/access.log main; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } chcon -R -t httpd_sys_rw_content_t /usr/share/nginx/html systemctl reload nginx * 修改 php 設定 vi /etc/php.ini : ;cgi.fix_pathinfo=1 cgi.fix_pathinfo=0 : [Date] : date.timezone = Asia/Taipei : * 修改 php-fpm 設定 vi /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 : : ; 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 : systemctl restart php-fpm systemctl enable php-fpm * 啟動 MariaDB 與驗證新密碼 systemctl restart mariadb systemctl enable mariadb mysql_secure_installation mysql -u root -p * 安裝其他 php 套件 yum install php-mysqlnd php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-zip php-curl php-cli systemctl restart php-fpm systemctl restart nginx ===== 下載最新版 Wordpress ===== * 下載網址 : http://wordpress.org/download/ yum install wget unzip cd /var/www/html/ wget http://wordpress.org/latest.zip unzip latest.zip chown -R nginx:nginx wordpress ===== 開始基本設定 ===== * 建立 wordpress db mysql -u root -p create database `wordpress`; create user 'wpadmin'@'localhost' identified by '**Password**'; grant all on wordpress.* to 'wpadmin'@'localhost'; flush privileges; quit * 透過網頁安裝設定 wordpress : http://xxx.xxx.xxx/wordpress <-- 依據只是經過三個步驟就可以安裝完成 * 使用 admin 與預設密碼(0adf3e 這樣的密碼) 登入, 先將預設密碼改成你要的密碼 ===== 設定固定網址 ===== * /etc/nginx/conf.d/default.conf : index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$args; } error_page 404 /404.html; : * 檢查設定檔與重啟 nginx nginx -t systemctl restart nginx ===== 設定特定 IP 可存取 wp-admin ===== * Exp. 開放 10.x.x.x 以及 172.16.x.x 可以進入 wp-admin 管理介面 * 編輯 /etc/nginx/conf.d/default.conf : location / { try_files $uri $uri/ /index.php?$args; } location /wp-admin/ { allow 10.0.0.0/8; allow 172.16.0.0/16; deny all; } location /wp-admin/admin-ajax.php { allow all; } error_page 404 /404.html; : * 重新啟動 nginx 讓設定生效 systemctl restart nginx ===== 評估外掛與相關資源 ===== * CDN 整合 * [[https://free.com.tw/cloudflare-wordpress-plugin/|Cloudflare 免費 WordPress 外掛教學,一鍵為網站快速套用最佳化設定]] * 數據統計 * https://wp2static.com/ * https://wordpress.org/plugins/wp-slimstat/ * 網站測速 * http://www.webkaka.com/UrlCheck.aspx * 網站優化 * https://wordpress.org/plugins/autoptimize/ * plugin 參考文章 * https://transbiz.com.tw/wordpress-plugin-%E6%8E%A8%E8%96%A6/ * 如果要更改網址 -> 參考 **[[tech/wordpress_move]]** * 如果要更改已經上傳的媒體(圖片, 檔案)檔名 -> 參考 **[[https://webcusp.com/how-to-easily-rename-uploaded-media-files-in-wordpress/|How to Easily Rename uploaded Media Files in WordPress]]** ====== 參考網址 ====== * http://blog.itist.tw/2016/01/installing-lemp-stack-with-centos-7-nginx-mariadb-php-7.html * https://computingforgeeks.com/how-to-install-php-7-3-on-centos-7-fedora/ * https://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Installation * http://benjr.tw/96885 * https://www.digitalocean.com/community/tutorials/how-to-increase-pagespeed-score-by-changing-your-nginx-configuration-on-ubuntu-16-04 {{tag>wordpress blog 安裝}}