下面给你一套从零部署 Linux + LNMP(Linux + Nginx + MySQL/MariaDB + PHP)网站的通用流程,适用于 CentOS / Rocky / Alma / Ubuntu / Debian。你可以按需选择手动部署或用一键脚本。
# 更新系统
apt update && apt upgrade -y # Ubuntu/Debian
yum update -y # CentOS
wget http://soft.vpser.net/lnmp/lnmp2.0.tar.gz
tar zxf lnmp2.0.tar.gz
cd lnmp2.0
./install.sh lnmp
安装过程选择:
安装完成后:
lnmp
apt install nginx -y
systemctl enable nginx
systemctl start nginx
apt install mysql-server -y
mysql_secure_installation
apt install php-fpm php-mysql -y
mkdir -p /www/wwwroot/example.com
chown -R www-data:www-data /www/wwwroot/example.com
vim /etc/nginx/sites-available/example.com
示例配置:
server {
listen 80;
server_name example.com;
root /www/wwwroot/example.com;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
启用配置:
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx
scp -r ./web root@ip:/www/wwwroot/example.com
echo "<?php phpinfo(); ?>" > /www/wwwroot/example.com/index.php
浏览器访问:
http://服务器IP
mysql -u root -p
CREATE DATABASE site_db;
CREATE USER 'site_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON site_db.* TO 'site_user'@'localhost';
FLUSH PRIVILEGES;
网站配置文件中填写:
数据库:site_db
用户:site_user
密码:password
apt install certbot python3-certbot-nginx -y
certbot --nginx -d example.com
# Nginx
systemctl restart nginx
# PHP
systemctl restart php-fpm
# MySQL
systemctl restart mysql
❌ 403 Forbidden
→ 目录权限或 index 文件问题
❌ 502 Bad Gateway
→ PHP-FPM 未启动或 socket 路径错误
❌ 网站打不开
→ 防火墙 / 安全组未放行 80/443
如果你告诉我:
我可以直接给你精确部署方案。