在 Debian 上安装 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 常见有三种方式:
APT 直接安装(推荐新手)、官方源码编译(适合定制)、一键脚本(如 LNMP.org)。
下面我先给你 最常用、最稳定的 APT 方式,适合 Debian 10/11/12。
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl wget gnupg2
sudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
浏览器访问服务器 IP,看到 Welcome to nginx 表示成功。
sudo apt install -y mariadb-server
sudo mysql_secure_installation
常用配置:
sudo 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
systemctl status php*-fpm
常见如:
php8.2-fpm
sudo nano /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/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
⚠️
php8.2-fpm.sock根据你的 PHP 版本调整
sudo nginx -t
sudo systemctl reload nginx
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
访问:
http://服务器IP/info.php
✅ 能看到 PHP 信息页面即成功
⚠️ 测试完建议删除:
sudo rm /var/www/html/info.php
systemctl status nginx
systemctl status mariadb
systemctl status php8.2-fpm
systemctl restart nginx
systemctl restart mariadb
systemctl restart php8.2-fpm
root 路径sudo chown -R www-data:www-data /var/www/html
php-fpm 正在运行fastcgi_pass sock 路径正确✅ 安装 Redis / Memcached
✅ 配置 HTTPS(Let’s Encrypt)
✅ 多 PHP 版本共存
✅ 使用 Docker 部署 LNMP
如果你愿意,可以告诉我:
我可以给你 最合适的一套方案 ✅