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语句创建数据库及用户:
1 2 3 |
create database wordpress; grant all privileges on wordpress.* to 'wordpress'@'10.10.200.%' identified by 'WordPress@123'; flush privileges; |
部署运行环境
安装PHP8.0
1 2 3 4 5 |
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的健康检查也是这么建议的。
1 2 3 4 |
# 依赖gcc # yum -y install gcc yum -y install ImageMagick ImageMagick-devel pecl install imagick |
安装imagick时有提示信息,按回车继续即可,安装成功后会提示需要在php.ini中加入如下参数(暂时不管):
1 |
extension=imagick.so |
配置PHP
修改配置文件/etc/php.ini:
1 2 3 4 |
[PHP] memory_limit = 1024M extension = imagick.so upload_max_filesize = 50M |
修改配置文件/etc/php-fpm.d/www.conf:
1 |
listen = 127.0.0.1:9000 |
启动PHP
1 2 |
systemctl start php-fpm systemctl enable php-fpm |
部署Nginx
1 |
yum -y install nginx |
配置nginx
修改NGINX主配置文件/etc/nginx/nginx.conf,所列出的参数都与wordpress优化相关:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
... 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:
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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
1 2 |
systemctl start nginx systemctl enable nginx |
部署Wordpress
下载wordpress
1 2 |
wget https://wordpress.org/latest.tar.gz tar zxvf latest.tar.gz |
设置权限
1 |
chown -R apache.apache wordpress |
现在访问站点开启Wordpress之旅吧!
原创文章禁止转载:技术学堂 » Linux+Nginx+MySQL+PHP搭建WordPress站点