温馨提示×

Debian LNMP怎样排错

小樊
42
2026-09-01 20:36:42
栏目: 智能运维

在 Debian 上搭建或使用 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 时,排错通常遵循“分层定位”的思路:先确认服务是否运行,再看日志,最后检查配置。下面给你一套实用排错流程


一、基础检查(先确认“活着没”)

1. 检查服务状态

systemctl status nginx
systemctl status mariadb   # 或 mysql
systemctl status php8.2-fpm  # 版本按实际

若未运行:

systemctl start nginx
systemctl enable nginx

二、Nginx 排错

2. 检查 Nginx 配置语法

nginx -t

常见错误:

  • duplicate location
  • fastcgi_pass 路径错误
  • root 指向不存在目录

3. 查看 Nginx 错误日志

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

常见错误:

  • Permission denied(目录权限)
  • connect() failed (111: Connection refused) → PHP-FPM 没跑
  • File not foundrootfastcgi_param SCRIPT_FILENAME

4. 权限问题排查

ps aux | grep nginx

Nginx 通常用户是 www-data

chown -R www-data:www-data /var/www
chmod -R 755 /var/www

三、PHP-FPM 排错

5. 确认 PHP-FPM 在监听

systemctl status php8.2-fpm

查看监听方式:

grep listen /etc/php/8.2/fpm/pool.d/www.conf

通常是:

listen = /run/php/php8.2-fpm.sock

6. Nginx 中必须匹配

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

7. PHP 日志

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

四、MySQL / MariaDB 排错

8. 能否连接

mysql -u root -p

若失败:

systemctl status mariadb
journalctl -xe

9. 常见错误

  • 启动失败:InnoDB 文件损坏
  • 密码错误:ALTER USER 重置
  • 远程连不上:检查 bind-address = 127.0.0.1

五、网站打不开的通用排查顺序

  1. 浏览器报什么?

    • 502 → PHP-FPM 没跑 / sock 不对
    • 503 → 资源耗尽
    • 404 → root / index 错
    • 空白页 → PHP 报错但未显示
  2. PHP 是否报错

<?php
phpinfo();

或开启错误显示:

display_errors = On
  1. 防火墙 / 端口
ss -tlnp | grep 80
ufw status

六、快速排错 checklist(收藏)

nginx -t
systemctl status
✅ 看 error.log
✅ PHP-FPM socket 匹配
✅ 文件权限是 www-data
✅ 数据库能本地连


如果你愿意,可以把具体报错信息(浏览器提示 / Nginx 日志 / PHP 日志)贴出来,我可以直接帮你定位到具体配置。

0