1 基础环境配置
1.1 最新版本的PHP编译安装
1.2 LNMP环境部署
注:PHP部分的rpm包不用安装配置
2 部署WordPress
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 编译并安装
makemake install | tee install.log
2.3 下载WordPress
cd ~wget https://wordpress.org/latest.tar.gz -O wordpress-4.9.1.tar.gz
注:最新版本的下载地址请参阅,
英文版本:
中文版本:
2.4 部署源代码
tar -xf wordpress-4.9.1.tar.gzmv 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 -pcreate 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 启用插件
后台单击【插件】->【已安装的插件】->【启用即可】
参阅文档:
----------------------------------------------