排查 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)环境故障,可以按 “分层定位、由外到内” 的思路进行。下面给你一套 系统化排查流程,适合生产环境也适合本地开发。
/var/log/nginx/php-fpm.log / php.error_logps -ef | grep nginx
ps -ef | grep php-fpm
ps -ef | grep mysqld
或:
systemctl status nginx
systemctl status php-fpm
systemctl status mysql
✅ 没运行就启动:
systemctl start nginx
systemctl start php-fpm
systemctl start mysql
ss -lntp
或:
netstat -lntp
常见端口:
✅ 如果端口没监听,说明服务没启动或配置错误。
iptables -L -n
# 或
firewall-cmd --list-all
云服务器还要检查:
nginx -t
✅ 如果报错,先看行号,再改配置。
tail -f /var/log/nginx/error.log
常见错误:
connect() failed (111: Connection refused) → PHP-FPM 没启动no live upstreams → upstream 配置错误403 Forbidden → 权限 / 目录错误404 Not Found → root / location 配置错误tail -f /var/log/nginx/access.log
看:
ps -ef | grep php-fpm
grep listen /etc/php-fpm.d/www.conf
常见两种:
listen = 127.0.0.1:9000
# 或
listen = /run/php-fpm/www.sock
✅ Nginx 必须一致:
fastcgi_pass 127.0.0.1:9000;
# 或
fastcgi_pass unix:/run/php-fpm/www.sock;
tail -f /var/log/php-fpm/error.log
常见错误:
pool www does not existpermission denied(sock 权限)在 PHP 文件中:
<?php
phpinfo();
如果空白:
php -v
php -m
mysql -u root -p
查看用户权限:
SELECT user, host FROM mysql.user;
tail -f /var/log/mysqld.log
chown -R nginx:nginx /var/www/html
chmod -R 755 /var/www/html
PHP 写目录(如 upload):
chmod -R 777 upload
getenforce
临时关闭测试:
setenforce 0
| 现象 | 可能原因 |
|---|---|
| 502 Bad Gateway | PHP-FPM 没启动 / 端口不一致 |
| 404 | root / location 配置错误 |
| 403 | 权限 / SELinux |
| 空白页 | PHP 报错 / display_errors 关闭 |
| 数据库连接失败 | MySQL 未启动 / 权限 |
| 连接超时 | 防火墙 / 安全组 |
nginx -tsystemctl status nginx php-fpm mysqltail -f /var/log/nginx/error.logtail -f /var/log/php-fpm/error.log如果你愿意,可以直接把 具体报错信息、系统版本、Nginx 配置 发出来,我可以 精准帮你定位到哪一行配置有问题。