96SEO 2025-09-05 11:32 2
在开始搭建LNMP与WordPress之前,我们需要准备以下环境:
先说说我们需要安装MySQL数据库。
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
接下来我们需要安装Nginx作为Web服务器。
yum install nginx -y
安装完成后 可以通过以下命令启动Nginx:
systemctl start nginx
然后我们需要安装PHP,以便能够处理PHP脚本。
yum install php php-fpm -y
配置Nginx以支持PHP。
server {
listen 80;
server_name your_domain_or_ip;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据PHP版本调整
}
}
编辑PHP-FPM配置文件,调整运行参数。
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
将WordPress解压到Nginx的根目录下比方说:
tar -zxvf wordpress-5.7.2-zh_CN.tar.gz -C /var/www/html/
访问安装页面填写数据库信息,完成安装。
为了提高网站平安性,建议配置SSL证书。
使用Let’s Encrypt获取免费证书,并配置Nginx支持HTTPS。
通过以上步骤, 你就可以将LNMP与WordPress完美搭配,搭建一个稳定、快速、平安的网站。
Demand feedback