下面给你一套从零搭建 LNMP + WordPress 的完整流程(适合 CentOS 7/8、Rocky、AlmaLinux,Ubuntu 略有差异我会标注)。
LNMP = Linux + Nginx + MySQL/MariaDB + PHP
# 关闭 SELinux(避免权限问题)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# 防火墙放行 80/443
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
yum install -y epel-release
yum install -y nginx
systemctl enable --now nginx
apt update
apt install -y nginx
systemctl enable --now nginx
浏览器访问服务器 IP,看到 Nginx 欢迎页说明成功。
yum install -y mariadb mariadb-server
systemctl enable --now mariadb
mysql_secure_installation
设置 root 密码,其余选 Y
mysql -uroot -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wp123456';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
yum install -y yum-utils
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php81
yum install -y php php-fpm php-mysql php-gd php-mbstring php-xml php-json
dnf install -y php php-fpm php-mysqlnd php-gd php-mbstring php-xml php-json
systemctl enable --now php-fpm
cd /usr/share/nginx/html
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
tar -zxvf latest-zh_CN.tar.gz
mv wordpress/* .
rm -rf wordpress latest-zh_CN.tar.gz
chown -R nginx:nginx /usr/share/nginx/html
chmod -R 755 /usr/share/nginx/html
编辑配置文件:
vi /etc/nginx/conf.d/wordpress.conf
示例配置(✅ 推荐):
server {
listen 80;
server_name yourdomain.com;
root /usr/share/nginx/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
测试并重载:
nginx -t
systemctl reload nginx
浏览器访问:
http://服务器IP
选择语言 → 填写数据库信息:
数据库名:wordpress
用户名:wpuser
密码:wp123456
数据库主机:localhost
表前缀:wp_
✅ 安装完成即可进入后台
tail -f /var/log/nginx/error.log
tail -f /var/log/php-fpm/error.log
chown -R nginx:nginx /usr/share/nginx/html
确认 Nginx 中已配置:
try_files $uri $uri/ /index.php?$args;
如果你愿意,我也可以帮你:
你现在用的是 CentOS 还是 Ubuntu?