在 CentOS 上,PHP 日志的位置取决于 PHP 的运行方式(PHP-FPM / Apache mod_php / CLI)以及你的配置。下面按常见情况说明:
一般在:
/var/log/php-fpm/error.log
或
/var/log/php-fpm/www-error.log
查看具体路径:
grep error_log /etc/php-fpm.conf
grep error_log /etc/php-fpm.d/www.conf
在 php.ini 中:
log_errors = On
error_log = /var/log/php_errors.log
查看 php.ini 位置:
php --ini
或
php-fpm -i | grep "Loaded Configuration File"
PHP 错误通常会写入 Apache 日志:
/var/log/httpd/error_log
也可以单独配置:
error_log = /var/log/php_errors.log
默认一般不写日志文件,错误直接输出到终端。
若配置了:
error_log = /var/log/php_cli.log
则在此文件中。
# 查找 php 相关日志
ls -l /var/log | grep php
# 查找 php.ini 中的 error_log
php -i | grep error_log
# 实时查看日志
tail -f /var/log/php-fpm/error.log
| 场景 | 日志位置 |
|---|---|
| PHP-FPM | /var/log/php-fpm/error.log |
| Apache | /var/log/httpd/error_log |
| 自定义 | php.ini 中 error_log |
| CLI | 终端 / 自定义文件 |
如果你愿意,可以告诉我:
我可以帮你精确定位并配置 PHP 日志。