1 基礎環境配置php
1.1 最新版本的PHP編譯安裝mysql
https://blog.51cto.com/cmdschool/2046062 nginx
1.2 LNMP環境部署sql
https://blog.51cto.com/cmdschool/1962061 數據庫
注:PHP部分的rpm包不用安裝配置apache
2 部署WordPressvim
2.1 添加WordPress須要的額外模塊安全
cd ~/php-7.1.12 ./configure --bindir=/usr/sbin/ \ --sbindir=/usr/sbin/ \ --sysconfdir=/etc/ \ --libdir=/usr/lib64/ \ --mandir=/usr/share/man/ \ --includedir=/usr/include/ \ --with-fpm-user=apache \ --with-fpm-group=apache \ --enable-fpm \ --with-mysqli \ --with-zlib=/usr/
2.2 編譯並安裝bash
make make install | tee install.log
2.3 下載WordPresside
cd ~ wget https://wordpress.org/latest.tar.gz -O wordpress-4.9.1.tar.gz
注:最新版本的下載地址請參閱,
英文版本:https://wordpress.org/download/
中文版本:https://cn.wordpress.org/txt-download/
2.4 部署源代碼
tar -xf wordpress-4.9.1.tar.gz mv wordpress/* /var/www/www.cmdschool.org/ chown root:apache -R /var/www/www.cmdschool.org/ chmod 775 -R /var/www/www.cmdschool.org/
2.5 建立數據庫
mysql -uroot -p create database wordpress character set utf8; grant all privileges on wordpress.* to 'wordpress'@'localhost' identified by 'wordpresspwd'; grant all privileges on wordpress.* to 'wordpress'@'127.0.0.1' identified by 'wordpresspwd'; flush privileges;
2.6 登陸並根據嚮導鏈接數據庫
O(∩_∩)O哈哈~,界面操做本身領悟哈!
2.7 登陸管理後臺
3 優化配置
3.1 安裝主題
3.1.1 安裝解壓工具
yum install -y unzip
3.1.2 下載主題
cd ~ wget https://downloads.wordpress.org/theme/imnews.1.12.zip
注:選擇主題,請訪問以下連接,
3.1.3 解壓主題
unzip imnews.1.12.zip
3.1.4 部署主題
cp -a imnews /var/www/www.cmdschool.org/wp-content/themes/ chown apache:apache -R /var/www/www.cmdschool.org/wp-content/themes/imnews/ chmod 775 -R /var/www/www.cmdschool.org/wp-content/themes/imnews/
注:通過以上操做,後臺管理便可單擊激活主題
3.1.5 激活主題
後臺單擊【外觀】->【主題】->【激活】便可啓用該主題
3.2 添加安全規則
3.2.1 添加全局目錄
mkdir /etc/nginx/global
3.2.2 全局目錄中建立安全規則
# Global restrictions configuration file. # Designed to be included in any server {} block. location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~ /\. { deny all; } # Deny access to any files with a .php extension in the uploads directory # Works in sub-directory installs and also in multisite network # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~* /(?:uploads|files)/.*\.php$ { deny all; }
3.2.3 引用安全規則
vim /etc/nginx/conf.d/www.cmdschool.org_80.conf
加入以下行:
server { [...] include global/restrictions.conf; }
3.3 配置連接重寫
3.3.1 關閉重寫技術
默認地WordPress開啓重寫技術,要關閉請在後臺單擊
Settings(設置)->Permalinks(固定連接)->Plain(樸素)http://www.cmdschool.org/?p=123
3.3.2 文章的重寫技術配置
登陸後當你發表第一篇文章你會發現文章詳情沒法訪問,若是要正常訪問請作以下選擇,
Settings(設置)->Permalinks(固定連接)->Numeric(數字)http://www.cmdschool.org/archives/123
而後,開啓Nginx的重寫功能:
vim /etc/nginx/conf.d/www.cmdschool.org_80.conf
加入以下代碼:
server { [...] rewrite ^/archives/(.*)$ /?p=$1? last; }
重載或者重啓Nginx服務:
systemctl reload nginx
3.3.3 文章翻頁的重寫技術配置
當你發表多篇文章時,你會發現文章翻頁沒法訪問,若是要正常訪問請作以下選擇,
Settings(設置)->Permalinks(固定連接)->Numeric(數字)http://www.cmdschool.org/archives/123
而後,單擊翻頁你會發現連接變成如下格式,
http://www.cmdschool.org/page/2
而後,開啓Nginx的重寫功能:
vim /etc/nginx/conf.d/www.cmdschool.org_80.conf
加入以下代碼:
server { [...] rewrite ^/page/(.*)$ /?paged=$1? last; }
重載或者重啓Nginx服務:
systemctl reload nginx
3.3.4 頁面的重寫技術配置
若是你在後臺新建了一個頁面,發現沒法訪問,我建議你作以下配置
頁面->編輯頁面,你會看到當前連接顯示以下:
http://www.cmdschool.org/about
首先,切換到樸素模式,
頁面->編輯頁面,你會看到以下連接
http://www.cmdschool.org/?page_id=164
而後經過以下重寫技術將about頁從新定位到頁面ID(164)
vim /etc/nginx/conf.d/www.cmdschool.org_80.conf
加入以下代碼:
server { [...] rewrite ^/about /?page_id=164 last; }
重載或者重啓Nginx服務:
systemctl reload nginx
而後經過再次切換模式
Settings(設置)->Permalinks(固定連接)->Numeric(數字)
經過以上操做,便可將/about的訪問重新定位到相應的頁面。
3.4 安裝寫做加強插件
3.4.1 下載插件
wget https://downloads.wordpress.org/plugin/tinymce-advanced.4.6.7.zip
3.4.2 解壓插件
unzip tinymce-advanced.4.6.7.zip
3.4.3 部署插件
cp -a tinymce-advanced /var/www/www.cmdschool.org/wp-content/plugins/
3.4.4 配置插件權限
chown apache:apache -R /var/www/www.cmdschool.org/wp-content/plugins/tinymce-advanced/ chmod 775 -R /var/www/www.cmdschool.org/wp-content/plugins/tinymce-advanced/
3.4.5 啓用插件
後臺單擊【插件】->【已安裝的插件】->【啓用便可】
參閱文檔:
----------------------------------------------
https://codex.wordpress.org/Nginx
https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/