在 CentOS 上排查 PHP 故障,核心思路是找到日志 → 看错误 → 定位代码/配置 → 验证修复。下面按常见场景一步步说。
不同方式,日志位置不一样:
php -v
which php
ps aux | grep php
常见三种:
查看 PHP-FPM 配置:
php-fpm -t
# 或
rpm -ql php-fpm | grep pool
通常路径:
/var/log/php-fpm/error.log
/var/log/php-fpm/www-error.log
查看:
tail -f /var/log/php-fpm/error.log
先找 php.ini:
php --ini
查看关键配置:
log_errors = On
error_log = /var/log/php_errors.log
display_errors = Off # 生产环境应为 Off
查看日志:
tail -f /var/log/php_errors.log
tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log
tail -f /var/log/httpd/error_log
tail -f /var/log/httpd/access_log
常见位置:
/var/www/html/storage/logs/
/var/www/html/runtime/log/
看 PHP-FPM / Nginx error.log 典型错误:
PHP Fatal errorAllowed memory size exhaustedCall to undefined function临时开启错误显示(调试用):
ini_set('display_errors', 1);
error_reporting(E_ALL);
或改 php.ini:
display_errors = On
systemctl status php-fpm
journalctl -xe
常见原因:
ls -l /var/log/php-fpm
ps aux | grep php-fpm
确保:
apache / nginx)正确# 1. 看实时错误
tail -f /var/log/php-fpm/error.log
tail -f /var/log/nginx/error.log
# 2. 复现问题
curl http://localhost/test.php
# 3. 根据错误定位代码
grep -R "错误信息" /var/www/html
# 4. 修复后重启
systemctl restart php-fpm
php -l file.php # 语法检查
php -i | grep error # 查看错误配置
strace -p <pid> # 深入调试(高级)
如果你愿意,可以告诉我:
我可以直接帮你定位问题。