Linux+Nginx+MySQL+PHP搭建WordPress站点

WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站,本文讲述在LNMP环境中搭建Wordpress站点的方法。

两台主机分别负责前端应用和后端数据库,遗憾的是在CentOS8.1下部署PHP7.3的时候遇到些问题,所以只好选择CentOS7.8。

主机列表 应用列表
10.10.200.1 PHP8.0,Nginx1.16.1
10.10.200.2 Mysql5.7.32

配置数据库

登录MySQL,执行以下SQL语句创建数据库及用户:

create database wordpress;
grant all privileges on wordpress.* to 'wordpress'@'10.10.200.%' identified by 'WordPress@123';
flush privileges;

部署运行环境

安装PHP8.0

yum -y install epel-release yum-utils
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php80
yum -y install php
yum -y install php-bcmath php-devel php-embedded php-fpm php-gd php-mbstring php-mysqlnd php-pear php-pecl-zip php-xml

安装imagick

强烈建议安装此扩展,因为wordpress的健康检查也是这么建议的。

# 依赖gcc
# yum -y install gcc
yum -y install ImageMagick ImageMagick-devel
pecl install imagick

安装imagick时有提示信息,按回车继续即可,安装成功后会提示需要在php.ini中加入如下参数(暂时不管):

extension=imagick.so

配置PHP

修改配置文件/etc/php.ini

[PHP]
memory_limit = 1024M
extension = imagick.so
upload_max_filesize = 50M

修改配置文件/etc/php-fpm.d/www.conf

listen = 127.0.0.1:9000

启动PHP

systemctl start php-fpm
systemctl enable php-fpm

部署Nginx

yum -y install nginx

配置nginx

修改NGINX主配置文件/etc/nginx/nginx.conf,所列出的参数都与wordpress优化相关:

...
http {
    ...

    server_tokens        off;
    client_max_body_size 50m;

    gzip            on;
    gzip_min_length 1k;
    gzip_buffers    32 8k;
    gzip_comp_level 3;
    gzip_types      text/plain text/css application/javascript application/xml+rss application/x-httpd-php image/jpeg image/png;
    gzip_types      application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
    gzip_vary       on;

    include /etc/nginx/conf.d/*.conf;
}

修改NGINX域名配置文件/etc/nginx/conf.d/wordpress.conf,后续将有文章讲述如何开启HTTPS:

    server {
        listen      80;
        listen      [::]:80;
        server_name olzl.net www.olzl.net;
        root        /www/wordpress;
        index       index.php;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location = /favicon.ico {
            expires       max;
            access_log    off;
            log_not_found off;
        }

        location = /robots.txt {
            allow         all;
            access_log    off;
            log_not_found off;
        }

        location ~ \.php {
            set $path_info "";
            set $real_script_name $fastcgi_script_name;
            if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                set $real_script_name $1;
                set $path_info $2;
            }
            include       fastcgi_params;
            include       fastcgi.conf;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_intercept_errors on;
            fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
            fastcgi_param SCRIPT_NAME $real_script_name;
            fastcgi_param PATH_INFO   $path_info;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires       max;
            access_log    off;
            log_not_found off;
        }

        location ~* ^.+\.(eot|ttf|otf|woff|svg)$ {
            expires       max;
            access_log    off;
        }

    }

启动nginx

systemctl start nginx
systemctl enable nginx

部署Wordpress

下载wordpress

wget https://wordpress.org/latest.tar.gz
tar zxvf latest.tar.gz

设置权限

chown -R apache.apache wordpress

现在访问站点开启Wordpress之旅吧!

原创文章禁止转载:技术学堂 » Linux+Nginx+MySQL+PHP搭建WordPress站点

赞 (0) 打赏

精彩评论

7+7=

感谢您的支持与鼓励

支付宝扫一扫打赏

微信扫一扫打赏