如何基于PHP 7.4部署WordPress?

WordPress

1基础环境配置

1.1最新版本的PHP编译安装

http://www.cmdschool.org/archives/55
注:需要“php-7.4.5”

1.2 LNMP环境部署

http://www.cmdschool.org/archives/1
注:PHP部分的转速包不用安装配置

2部署WordPress

2.1添加WordPress需要的额外模块

cd ~/php-7.4.5
./configure --bindir=/usr/sbin/ \
            --sbindir=/usr/sbin/ \
            --libexecdir=/usr/libexec \
            --sysconfdir=/etc/ \
            --localstatedir=/var \
            --libdir=/usr/lib64/  \
            --includedir=/usr/include/ \
            --datarootdir=/usr/share \
            --infodir=/usr/share/info \
            --localedir=/usr/share/locale \
            --mandir=/usr/share/man/ \
            --docdir=/usr/share/doc/php \
            --with-fpm-user=apache \
            --with-fpm-group=apache \
            --enable-fpm \
            --with-mysqli \
            --with-zlib=/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: Package requirements (sqlite3 > 3.7.4) were not met:
No package 'sqlite3' found

可通过如下命令解决依赖关系,

yum install -y sqlite-devel

如果遇到以下提示,

configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found

可参阅如下章节解决依赖关系,
https://www.cmdschool.org/archives/9902
如果遇到以下提示,

configure: error: off_t undefined; check your library configuration

可通过如下命令解决,

echo '/usr/local/lib64' > /etc/ld.so.conf.d/php.conf
echo '/usr/local/lib' >> /etc/ld.so.conf.d/php.conf
echo '/usr/lib' >> /etc/ld.so.conf.d/php.conf
echo '//usr/lib64' >> /etc/ld.so.conf.d/php.conf
ldconfig -v

如果遇到以下提示,

/usr/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory
 #include 
                     ^

可通过如下命令解决依赖关系,

ln -s /usr/lib64/libzip/include/zipconf.h /usr/include/

2.2编译并安装

make
make install | tee install.log

2.3 加载模块

2.3.1 准备模块编译环境

请参阅如下链接准备模块编译环境或熟悉模块的安装方法,
https://www.cmdschool.org/archives/3166

2.3.2 编码gd模块

cd ~/php-7.4.5/ext/gd
phpize
./configure
make
make install
echo 'extension=gd.so' >> /etc/php.ini

2.3.3 编码zip模块

cd ~/php-7.4.5/ext/zip
phpize
./configure
make
make install
echo 'extension=gd.so' >> /etc/php.ini

如果遇到如下错误提示,

configure: error: Package requirements (libzip >= 0.11) were not met:
No package 'libzip' found

可参阅如下章节解决此依赖关系,
https://www.cmdschool.org/archives/9924

2.3.4 编码imagick模块

可参阅如下章节解决此依赖关系,
https://www.cmdschool.org/archives/2795
注:需要“imagick-3.4.4”

2.4 下载WordPress

cd~
wget https://cn.wordpress.org/latest-zh_CN.tar.gz -O wordpress-5.4.1-zh_CN.tar.gz

注:最新版本的下载地址请参阅,
https://wordpress.org/download/

2.4 部署源代码

tar -xf wordpress-5.4.1-zh_CN.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.5.4.0.zip

注:选择插件,请访问如下链接,
https://wordpress.org/plugins/

3.4.2 解压插件

unzip tinymce-advanced.5.4.0.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/

没有评论

发表评论

WordPress
如何安装WordPress的百度统计?

1 前言 一个问题,一篇文章,一出故事。 笔者的WordPress想要安装Baidu统计,于是整理此 …

Reverse Proxy
如何用Nginx反向代理WordPress?

1 前言 一个问题,一篇文章,一出故事。 笔者的WordPress安装Google的Site Kit …

WordPress
如何配置WordPress的Authorize插件?

1 插件介绍 1.1 Authorize的简介 用于授权特定的用户访问WordPress网站 1.2 …