调试 Linux 下的 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 环境,通常要从分层排查入手:先看网络,再看 Nginx,再看 PHP,最后看数据库。下面给你一套实用调试思路和常用命令。
systemctl status nginx
systemctl status php-fpm
systemctl status mysql
或(老版本):
service nginx status
service php-fpm status
service mysql status
netstat -tunlp | grep -E '80|443|3306|9000'
# 或
ss -tunlp
LNMP 常见端口:
nginx -t
tail -f /var/log/nginx/error.log
常见错误:
Permission denied → 权限或 SELinux 问题File not found → root 路径或 PHP 配置错误connect() failed (111: Connection refused) → PHP-FPM 没启动tail -f /var/log/nginx/access.log
ps aux | grep php-fpm
新建测试文件:
echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
访问:
http://服务器IP/info.php
php -i | grep error_log
tail -f /var/log/php-fpm/error.log
php.ini:
display_errors = On
error_reporting = E_ALL
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
# 或
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
检查:
mysql -u root -p
tail -f /var/log/mysqld.log
# 或
tail -f /var/log/mysql/error.log
检查:
127.0.0.1 vs localhostfirewall-cmd --list-all
# 或
iptables -L
开放端口:
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
getenforce
setenforce 0 # 临时关闭测试
✅ 网页打不开
→ 看 Nginx error.log
✅ 空白页
→ 看 PHP 错误日志 / 开 display_errors
✅ 502 Bad Gateway
→ PHP-FPM 挂了或 socket 权限问题
✅ 数据库连接失败
→ 用户权限 / 端口 / 防火墙
如果你愿意,可以告诉我:
我可以直接帮你定位具体问题。