在 Linux 上使用 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 建站,一般流程如下。下面以 CentOS / Ubuntu 常见环境为例,适合新手操作。
wget http://soft.vpser.net/lnmp/lnmp2.0.tar.gz
tar zxf lnmp2.0.tar.gz
cd lnmp2.0
./install.sh lnmp
按提示选择:
安装完成后:
lnmp
可管理 Nginx / MySQL / PHP
sudo apt update
sudo apt install nginx mysql-server php-fpm php-mysql
启动服务:
systemctl start nginx
systemctl start mysql
systemctl start php-fpm
lnmp vhost add
按提示输入:
www.example.com)/home/wwwroot/域名)例如:
cd /home/wwwroot/www.example.com
把 WordPress / Typecho / 自己的 PHP 项目放进去
示例(WordPress):
wget https://wordpress.org/latest.tar.gz
tar zxvf latest.tar.gz
mv wordpress/* .
mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARSET utf8mb4;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
示例 Nginx 配置:
server {
listen 80;
server_name www.example.com;
root /home/wwwroot/www.example.com;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
重载 Nginx:
nginx -t
systemctl reload nginx
http://www.example.com
✅ 403 错误
chown -R www:www /home/wwwroot
✅ PHP 不解析
php-fpm 是否运行fastcgi_pass 路径是否正确✅ 无法连接数据库
如果你告诉我:
我可以直接给你一步步命令版教程。