在 CentOS 上,PHP 日志的解读方式主要取决于 PHP 的运行模式(CLI / Apache / php-fpm)以及你的日志配置。下面按常见场景给你一个“能直接用”的说明。
php --ini
或
php -i | grep "Loaded Configuration File"
查找以下两项:
error_log = /var/log/php/php_errors.log
log_errors = On
display_errors = Off
/var/log/php-fpm/error.log
/var/log/php-fpm/www-error.log
/var/log/httpd/error_log
/var/log/php/php_cli.log
或直接输出到终端PHP 错误日志一般长这样:
[10-Oct-2024 14:22:31] WARNING: [pool www] child 1234 exited on signal 11 (SIGSEGV)
[10-Oct-2024 14:25:10] PHP Warning: file_get_contents(/a.txt): failed to open stream: No such file or directory in /var/www/test.php on line 12
[10-Oct-2024 14:26:01] PHP Fatal error: Uncaught Error: Call to undefined function abc() in /var/www/test.php:20
| 部分 | 说明 |
|---|---|
[时间] |
错误发生时间 |
PHP Warning / Error / Notice |
错误级别 |
file_get_contents |
出错函数 |
in /path/file.php on line X |
出错文件和行号 |
PHP Notice: Undefined variable: a in test.php on line 5
✅ 通常不影响运行
❌ 代码不规范
PHP Warning: mysqli_connect(): Connection refused
✅ 脚本继续执行
❌ 功能可能异常
PHP Fatal error: Allowed memory size exhausted
❌ 脚本直接终止
PHP Parse error: syntax error, unexpected ';'
❌ 根本跑不起来
child 1234 exited on signal 11 (SIGSEGV)
可能原因:
execution timed out (60 sec)
解决:
max_execution_time = 300
tail -f /var/log/php-fpm/error.log
grep "PHP" /var/log/php-fpm/www-error.log
grep "PHP" error.log | awk '{print $2,$3}' | sort | uniq -c
display_errors = Off
log_errors = On
error_log = /var/log/php/php_errors.log
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
如果你愿意,可以把具体的 PHP 日志内容贴出来,我可以直接帮你逐行分析是哪里出的问题。