1基础环境配置
1.1最新版本的PHP编译安装
http://www.cmdschool.org/archives/55
1.2 LNMP环境部署
http://www.cmdschool.org/archives/1
注:PHP部分的转速包不用安装配置
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 \ --with-gd=/usr \ --with-jpeg-dir=/usr \ --with-webp-dir=/usr \ --with-png-dir=/usr \ --with-xpm-dir=/usr \ --with-freetype-dir=/usr \ --with-curl=/usr \ --with-openssl=/usr \ --enable-sockets \ --enable-exif \ --enable-mbstring \ --enable-zip
另外,你可能需要根据提示使用如下命令解决以下依赖关系,
yum install -y gd libjpeg-devel libwebp-devel libpng-devel libXpm-devel freetype-devel libcurl-devel openssl-devel
如果遇到如下提示,
configure: error: Unable to find gd.h anywhere under /usr/
请参阅以下文章安装GD,
https://www.cmdschool.org/archives/2779
2.2编译并安装
make make install | tee install.log
2.3下载WordPress
cd~ wget https://wordpress.org/latest.tar.gz -O wordpress-4.9.1.tar.gz
注:最新版本的下载地址请参阅,
https://wordpress.org/download/
2.4部署源代码
tar -xf wordpress-4.9.1.tar.gz mv wordpress / * /var/www/www.cmdschool.org/ chown apache: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
注:选择主题,请访问如下链接,
https://wordpress.org/themes/
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.2.4 重启服务使配置生效
systemctl restart nginx
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
然后Nginxi中加入如下重写技术:
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; }
然后通过再次切换模式
Settings(设置)->Permalinks(固定链接)->Numeric(数字)
3.3.5 RSS重写配置
RSS有两个页面需要通过从写才能正常使用,
http://www.cmdschool.org/?feed=rss2
http://www.cmdschool.org/?feed=comments-rss2
然后通过如下重写技术将about页重新定位到文章ID(164),
vim /etc/nginx/conf.d/www.cmdschool.org_80.conf
加入如下代码:
server { [...] rewrite ^/feed /?feed=rss2 last; rewrite ^/comments/feed /?feed=comments-rss2 last; }
然后通过再次切换模式
Settings(设置)->Permalinks(固定链接)->Numeric(数字)
通过以上操作,即可从首页点击RSS从新定位到相应的页面。
3.4 安装写作增强插件
3.4.1 下载插件
wget https://downloads.wordpress.org/plugin/tinymce-advanced.4.6.7.zip
注:选择插件,请访问如下链接,
https://wordpress.org/plugins/
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 770 -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/
没有评论