“调试 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)”通常指定位并解决网站打不开、502/504、PHP 报错、数据库连不上等问题。下面按「分层排查 → 常用命令 → 典型问题」给你一套实用调试思路。
请求流程一般是:
浏览器 → Nginx → PHP-FPM → PHP 代码 → MySQL
哪一层断,就从哪一层查。
systemctl status nginx
systemctl status php-fpm
systemctl status mysql
或
ps aux | grep -E 'nginx|php-fpm|mysqld'
没运行就启动:
systemctl start nginx php-fpm mysql
nginx -t
tail -f /var/log/nginx/error.log
常见错误:
permission denied → 权限问题no such file → root 路径错connect() failed (111) → PHP-FPM 没起nginx.conf 或 server 块中:
error_log /var/log/nginx/error.log debug;
php -v
php -m
systemctl status php-fpm
journalctl -u php-fpm -f
php -i | grep error_log
或看 php.ini:
display_errors = On
error_log = /var/log/php/php-error.log
echo "<?php phpinfo();" > /usr/share/nginx/html/info.php
浏览器访问:
http://ip/info.php
fastcgi_pass 地址错(socket 或端口)mysql -u root -p
tail -f /var/log/mysqld.log
或
journalctl -u mariadb
检查:
localhost(用 socket)还是 127.0.0.1SELECT user,host FROM mysql.user;
ps aux | grep nginx
通常是 www-data 或 nginx
chown -R nginx:nginx /usr/share/nginx/html
chmod -R 755 /usr/share/nginx/html
setenforce 0
或
audit2why < /var/log/audit/audit.log
netstat -tunlp | grep -E '80|443|9000|3306'
firewall-cmd --list-all
| 现象 | 可能原因 |
|---|---|
| 403 | 目录无索引文件 / 权限不足 |
| 404 | root 路径错 |
| 500 | PHP 代码报错 |
| 502 | PHP-FPM 挂了 |
| 504 | PHP 执行超时 |
| 连不上 DB | 账号/权限/防火墙 |
nginx -ttail -f /var/log/nginx/error.logsystemctl status php-fpmtail -f php-error.logmysql -u xxx -p如果你愿意,可以告诉我:
我可以直接帮你定位具体错误。