在 CentOS 上分析 PHP 日志,一般分三类:PHP 错误日志、PHP-FPM 日志、Web 服务器(Nginx/Apache)日志。下面按常见场景一步步说明。
php -i | grep "Loaded Configuration File"
常见路径:
/etc/php.ini
/etc/php.d/*.ini
查找日志路径:
grep -R "error_log" /etc/php.ini /etc/php.d/
常见配置项:
log_errors = On
error_log = /var/log/php/error.log
error_reporting = E_ALL
✅ 如果没配置 error_log,PHP 错误可能写入 Web 服务日志。
php-fpm -t
常见路径:
/etc/php-fpm.conf
/etc/php-fpm.d/www.conf
查找日志:
grep -R "error_log" /etc/php-fpm.conf /etc/php-fpm.d/
常见配置:
error_log = /var/log/php-fpm/error.log
/var/log/nginx/error.log
/var/log/nginx/access.log
如果 PHP 报错但页面空白,通常在这里能看到 FastCGI 错误。
/var/log/httpd/error_log
/var/log/httpd/access_log
tail -f /var/log/php/error.log
grep -i "error\|exception\|fatal" /var/log/php/error.log
grep "2025-01-20" /var/log/php/error.log
awk '{print $1}' /var/log/php/error.log | sort | uniq -c | sort -nr
tail -f /var/log/nginx/error.log | grep php
常见错误:
FastCGI sent in stderrPHP Fatal errorAllowed memory size exhaustedPHP Fatal error: Allowed memory size exhausted
✅ 解决:
memory_limit = 256M
failed to open stream: Permission denied
✅ 解决:
chown -R nginx:nginx /var/www/html
chmod -R 755 /var/www/html
systemctl status php-fpm
journalctl -xe
goaccess /var/log/nginx/access.log
tail -f /var/log/php/error.log /var/log/nginx/error.log
tail -f 实时复现问题Fatal / Warning / Error如果你愿意,可以告诉我:
我可以 直接帮你定位问题。