“调试 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)”通常指定位并解决访问错误、性能问题或配置异常。下面按排查思路 + 常用命令 + 常见故障给你一套实用调试方法。
systemctl status nginx
systemctl status php-fpm
systemctl status mysql
或(老系统):
service nginx status
systemctl restart nginx
systemctl restart php-fpm
systemctl restart mysql
tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log
常见错误:
Permission denied → 权限问题File not found → root / index 配置错误connect() failed (111: Connection refused) → PHP-FPM 没起php -i | grep error_log
php-fpm 日志:
tail -f /var/log/php-fpm/error.log
PHP 本身错误:
<?php
phpinfo();
或临时开启:
ini_set('display_errors', 1);
error_reporting(E_ALL);
tail -f /var/log/mysql/error.log
测试连接:
mysql -u root -p
curl http://localhost
若返回 Nginx 默认页 → Nginx OK
新建:
vim /usr/share/nginx/html/info.php
<?php phpinfo(); ?>
访问:
http://服务器IP/info.php
看不到页面 → PHP-FPM 配置问题
ps aux | grep php-fpm
Nginx 配置中应有:
fastcgi_pass unix:/run/php-fpm/www.sock;
检查 sock 文件是否存在:
ls -l /run/php-fpm/www.sock
<?php
$conn = new mysqli("localhost", "user", "pass");
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "MySQL OK";
?>
原因:
解决:
systemctl restart php-fpm
chown -R nginx:nginx /var/www/html
chmod -R 755 /var/www/html
工具:
top
htop
iotop
mysqltuner
tcpdump:抓包strace -p php-fpm_pid:追踪系统调用nginx -t:检查配置php-fpm -tLNMP 调试 = 看日志 + 分层测 + 权限配置查
如果你有具体报错信息或场景(如 502、访问慢、WordPress 白屏),可以直接发出来,我可以帮你精准定位。