1 基础环境配置
1.1 最新版本的PHP编译安装
http://blog.51cto.com/cmdschool/2046062
1.2 LNMP环境部署
http://blog.51cto.com/cmdschool/1962061
注:PHP部分的rpm包不用安装配置
2 部署WordPress
2.1 添加WordPress需要的额外模块
1
2
3
4
5
6
7
8
9
10
11
12
|
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 编译并安装
1
2
|
make
make
install
|
tee
install
.log
|
2.3 下载WordPress
1
2
|
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 部署源代码
1
2
3
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 创建数据库
1
2
3
4
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 安装解压工具
1
|
yum
install
-y unzip
|
3.1.2 下载主题
1
2
|
cd
~
wget https:
//downloads
.wordpress.org
/theme/imnews
.1.12.zip
|
注:选择主题,请访问如下链接,
3.1.3 解压主题
1
|
unzip imnews.1.12.zip
|
3.1.4 部署主题
1
2
3
|
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 添加全局目录
1
|
mkdir
/etc/nginx/global
|
3.2.2 全局目录中创建安全规则
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# 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 引用安全规则
1
|
vim
/etc/nginx/conf
.d
/www
.cmdschool.org_80.conf
|
加入如下行:
1
2
3
4
|
server {
[...]
include global
/restrictions
.conf;
}
|
3.3 配置链接重写
3.3.1 关闭重写技术
默认地WordPress开启重写技术,要关闭请在后台单击
1
|
Settings(设置)->Permalinks(固定链接)->Plain(朴素)http:
//www
.cmdschool.org/?p=123
|
3.3.2 文章的重写技术配置
登录后当你发表第一篇文章你会发现文章详情无法访问,如果要正常访问请做如下选择,
1
|
Settings(设置)->Permalinks(固定链接)->Numeric(数字)http:
//www
.cmdschool.org
/archives/123
|
然后,开启Nginx的重写功能:
1
|
vim
/etc/nginx/conf
.d
/www
.cmdschool.org_80.conf
|
加入如下代码:
1
2
3
4
|
server {
[...]
rewrite ^
/archives/
(.*)$ /?p=$1? last;
}
|
重载或者重启Nginx服务:
1
|
systemctl reload nginx
|
3.3.3 文章翻页的重写技术配置
当你发表多篇文章时,你会发现文章翻页无法访问,如果要正常访问请做如下选择,
1
|
Settings(设置)->Permalinks(固定链接)->Numeric(数字)http:
//www
.cmdschool.org
/archives/123
|
然后,单击翻页你会发现链接变成以下格式,
1
|
http:
//www
.cmdschool.org
/page/2
|
然后,开启Nginx的重写功能:
1
|
vim
/etc/nginx/conf
.d
/www
.cmdschool.org_80.conf
|
加入如下代码:
1
2
3
4
|
server {
[...]
rewrite ^
/page/
(.*)$ /?paged=$1? last;
}
|
重载或者重启Nginx服务:
1
|
systemctl reload nginx
|
3.3.4 页面的重写技术配置
如果你在后台新建了一个页面,发现无法访问,我建议你做如下配置
页面->编辑页面,你会看到当前链接显示如下:
http://www.cmdschool.org/about
首先,切换到朴素模式,
页面->编辑页面,你会看到如下链接
http://www.cmdschool.org/?page_id=164
然后通过如下重写技术将about页重新定位到页面ID(164)
1
|
vim
/etc/nginx/conf
.d
/www
.cmdschool.org_80.conf
|
加入如下代码:
1
2
3
4
|
server {
[...]
rewrite ^
/about
/?page_id=164 last;
}
|
重载或者重启Nginx服务:
1
|
systemctl reload nginx
|
然后通过再次切换模式
1
|
Settings(设置)->Permalinks(固定链接)->Numeric(数字)
|
通过以上操作,即可将/about的访问从新定位到相应的页面。
3.4 安装写作增强插件
3.4.1 下载插件
1
|
wget https:
//downloads
.wordpress.org
/plugin/tinymce-advanced
.4.6.7.zip
|
3.4.2 解压插件
1
|
unzip tinymce-advanced.4.6.7.zip
|
3.4.3 部署插件
1
|
cp
-a tinymce-advanced
/var/www/www
.cmdschool.org
/wp-content/plugins/
|
3.4.4 配置插件权限
1
2
|
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 启用插件
后台单击【插件】->【已安装的插件】->【启用即可】