以下是LNMP与WordPress完美搭配的详细指南:
选择Ubuntu/CentOS等Linux发行版,确保服务器有公网IP并完成基础网络配置。
sudo apt update && sudo apt install nginx
sudo yum install epel-release && sudo yum install nginx
sudo systemctl start nginx && sudo systemctl enable nginx
。sudo apt install mysql-server
sudo yum install mariadb-server
sudo mysql_secure_installation
,设置root密码。sudo apt install php-fpm php-mysql
sudo yum install php php-mysqlnd php-fpm
php.ini
,确保cgi.fix_pathinfo=0
,重启PHP-FPM:sudo systemctl restart php-fpm
。编辑Nginx配置文件(如/etc/nginx/sites-available/default
):
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/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据PHP版本调整
}
location ~* \.(jpg|jpeg|png|gif|css|js)$ {
expires 30d;
}
}
测试配置并重启Nginx:sudo nginx -t && sudo systemctl restart nginx
。
cd /var/www/html
wget https://cn.wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress/* . && rm -rf wordpress latest.tar.gz
。sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
```。
cp wp-config-sample.php wp-config.php
wp-config.php
,填入数据库信息:define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
```。
fastcgi_cache
相关指令。fastcgi_pass
路径是否正确,确保PHP-FPM服务运行。通过以上步骤,可实现LNMP与WordPress的高效搭配,满足网站搭建需求。