温馨提示×

Debian LNMP为何启动失败

小樊
60
2026-07-15 17:41:53
栏目: 智能运维

Debian 上 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)启动失败 的原因很多,需要按组件逐个排查。下面我按最常见原因 → 排查方法 → 解决办法给你一个系统性的排查清单。


一、先确认是哪一部分没启动

分别在终端执行:

systemctl status nginx
systemctl status mariadb   # 或 mysql
systemctl status php-fpm

看哪个是 failed / inactive


二、Nginx 启动失败(最常见)

1️⃣ 配置文件错误

nginx -t

如果看到:

nginx: [emerg] unknown directive
nginx: configuration file /etc/nginx/nginx.conf test failed

✅ 解决办法:

  • 检查 /etc/nginx/sites-enabled/ 里的配置
  • 检查 fastcgi_pass 是否指向正确的 PHP-FPM socket

2️⃣ 端口被占用(80 / 443)

ss -lntp | grep :80

✅ 解决:

systemctl stop apache2
systemctl disable apache2

或改 Nginx 端口。


3️⃣ 日志查看

tail -n 50 /var/log/nginx/error.log

三、MySQL / MariaDB 启动失败

1️⃣ 查看状态

systemctl status mariadb

2️⃣ 常见原因

❌ 数据目录权限错误

chown -R mysql:mysql /var/lib/mysql

❌ 磁盘空间满

df -h

❌ 配置文件错误

mysqld --verbose --help | grep my.cnf

✅ 检查:

/etc/mysql/my.cnf
/etc/mysql/mariadb.conf.d/

3️⃣ 查看错误日志

tail -n 50 /var/log/mysql/error.log

四、PHP-FPM 启动失败

1️⃣ 检查版本

systemctl status php8.2-fpm

(版本可能是 7.4 / 8.1 / 8.2)


2️⃣ 常见错误

❌ socket 文件不存在

Nginx 里:

fastcgi_pass unix:/run/php/php8.2-fpm.sock;

检查:

ls /run/php/

✅ 如果不存在:

systemctl restart php8.2-fpm

3️⃣ 查看 PHP-FPM 日志

tail -n 50 /var/log/php8.2-fpm.log

五、LNMP 整体无法访问网站

如果是 服务都启动了,但访问 502 / 404

502 Bad Gateway

通常是:

  • PHP-FPM 没启动
  • socket 路径不一致
  • 权限不足

✅ 解决:

chmod 755 /run/php

六、Debian 特有常见问题

1️⃣ AppArmor 拦截(少见但坑)

aa-status

临时测试:

systemctl stop apparmor

2️⃣ 系统重启后服务没启动

systemctl enable nginx mariadb php8.2-fpm

七、快速自检清单(建议照着做)

nginx -t
systemctl restart nginx mariadb php8.2-fpm
ss -lntp
df -h

八、如果你愿意,我可以直接帮你定位

请把以下信息贴出来(越全越好):

  1. Debian 版本(cat /etc/debian_version
  2. 报错截图或日志
  3. systemctl status nginx mariadb php-fpm
  4. nginx -t 输出
  5. 是否 新装 还是 之前正常突然失败

我可以直接帮你精准定位是哪一步出错

0