安装与配置WordPress

安装php

yum install libxml2 libxml2-devel \
    sqlite sqlite-devel \
    curl libcurl-devel \
    libicu libicu-devel \
    oniguruma oniguruma-devel \
    libzip libzip-devel \
    libpng libpng-devel

注意: ​ 以下两个包可能不在epel里面,如果不在需要单独下载安装 下载地址:
http://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/

https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/

yum install libtidy-devel-5.6.0-5.el8.x86_64.rpm libtidy-5.6.0-5.el8.x86_64.rpm

编译脚本

./configure --prefix=/opt/php7 --enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl --enable-mbstring --enable-soap --with-zip --enable-calendar --enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli --with-pdo-mysql --with-openssl --with-curl --enable-gd --with-gettext --with-mhash --with-openssl --with-tidy --with-xmlrpc

# make # make install

配置

配置php

1、拷贝一些配置

​ 注意:上面编译php的时候,我指定的安装路径是/opt/php7

cp /opt/php7/etc/php-fpm.conf.default /opt/php7/etc/php-fpm.conf

2、配置 www.conf

cp /opt/php7/etc/php-fpm.d/www.conf.default /opt/php7/etc/php-fpm.d/www.conf
vim /opt/php7/etc/php-fpm.d/www.conf
    [www]
    变更为
    [nobody]

    user = nobody
    group = nobody

2、修改相关配置文件

cp /opt/soft/php-7.4.29/php.ini-development /opt/php7/php.ini
vim /opt/php7/php.ini
    cgi.fix_pathinfo=1
    变更为
    cgi.fix_pathinfo=0
配置nginx
# 同时注意nginx的权限
user  nobody;

client_max_body_size 100m;

upstream php {
    server 127.0.0.1:9000;
}

server {
    listen  80;
    server_name  localhost;

    location / {
        root /opt/html/wordpress;
        index index.html index.htm index.php;

        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }
       try_files $uri $uri/ /index.php?$args;
     }

    location ~ \.php$ {
        root /opt/html/wordpress;
        try_files $uri = 404;
        include fastcgi_params;
        fastcgi_pass php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #add_header Content-Security-Policy upgrade-insecure-requests;
    }
}

注意:在没有安装Really Simple SSL插件以前,如果你的网站使用了https,那么就需要将上面注释add_header的那一行去掉,否则将无法配置;
但是在安装完成Really Simple SSL插件以前,再将它注释了即可。

配置测试页面

# mkdir -p /opt/html
# echo "<?php phpinfo(); ?>" > /opt/html/index.php

启动php-fpm

# /opt/php7/sbin/php-fpm # ps aux | grep php-fpm

# 显示效果如下
root     2585609  0.0  0.1 176252 10900 ?        Ss   21:33   0:00 php-fpm: master process (/opt/php7/etc/php-fpm.conf)
nobody   2585610  0.0  0.2 201524 16476 ?        S    21:33   0:00 php-fpm: pool nobody
nobody   2585611  0.0  0.1 201524 13684 ?        S    21:33   0:00 php-fpm: pool nobody
root     2596329  0.0  0.0  12112  1088 pts/0    S+   22:28   0:00 grep --color=auto php
启动 nginx

# /opt/nginx/sbin/nginx -s reload
测试地址:http://xxx:7002

生成数据库及创建用户

为了避免以后的不必要的问题,尽可能使用mariadb

drop database wordpress;
create database wordpress;
create user wordpress@'127.0.0.1' identified by '此处设置密码';
create user wordpress@'%' identified by '此处设置密码';
grant all on wordpress.* to wordpress@'%' identified by '此处设置密码';
grant all on wordpress.* to wordpress@'127.0.0.1' identified by '此处设置密码';
flush privileges;

注意在wordpress的引导中要填写的数据库的地址必须为127.0.0.1,不要填写localhost,否则可能导致数据库连接失败而无法继续。

安装wordpress

下载最新的安装包并且解压后拷贝到文件夹/opt/html目录下

tar zxvf latest.tar.gz
mv wordpress/* /opt/html/

打开浏览器即可使用图形界面进行安装

一些插件
1、Really Simple SSL
    wordpress的https支持
2、Disable Comments
    关闭评论区

优化php

需要事先查看php启动的时候,去哪一个目录寻找php.ini文件。
# strace /opt/php7/bin/php-fpm -i 2 > my.log
# grep -i "php.ini" my.log

Configuration File (php.ini) Path => /opt/php7/lib

通过以上的方式我们知道当前php-fpm的命令查找php.ini的目录是/opt/php7/lib,执行以下操作
# cp /opt/php7/etc/php.ini /opt/php7/lib
# vim /opt/php7/lib/php.ini
且更改以下几个字段

#设置内存
memory_limit = 2048M

#设置上传
post_max_size = 200M
upload_max_filesize = 100M
max_file_uploads = 20

需要重新启动php-fpm