下面给你一个**在 Debian 系统上部署 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)**的完整、实战型流程,适用于 Debian 11 / 12,服务器或云主机均可。
apt update && apt upgrade -y
apt install -y curl wget unzip vim
apt install -y nginx
systemctl enable nginx
systemctl start nginx
浏览器访问服务器 IP:
http://服务器IP
看到 Welcome to nginx 即成功。
apt install -y mariadb-server
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation
按提示操作:
apt install -y php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip
Debian 12 默认 PHP 8.2
Debian 11 默认 PHP 7.4
php -v
systemctl status php*-fpm
vim /etc/nginx/sites-available/example.conf
示例配置(重点):
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/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
nginx -t
systemctl reload nginx
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
浏览器访问:
http://服务器IP/info.php
✅ 看到 PHP 信息页面即 LNMP 部署成功。
ufw allow 80
ufw allow 443
ufw reload
fastcgi_pass 路径是否正确systemctl status php*-fpm
chown -R www-data:www-data /var/www/html
✅ 你现在拥有:
一个标准 LNMP 环境已部署完成 ✅
如果你需要:
告诉我你的使用场景,我可以给你定制方案。