在 CentOS 上,PHP 日志的位置取决于你是 PHP-FPM 还是 Apache + mod_php,以及你的具体配置。下面是最常见的查找方式:
/var/log/php-fpm/error.log
或(某些版本):
/var/log/php-fpm/www-error.log
如果找不到,可以用:
find /var/log -name "*php*"
php-fpm -i | grep "error_log"
或查看配置文件:
grep -R "error_log" /etc/php-fpm.d/
grep -R "error_log" /etc/php-fpm.conf
示例配置:
error_log = /var/log/php-fpm/error.log
通常在 www.conf 中配置:
grep -R "php_admin_value\[error_log\]" /etc/php-fpm.d/
或:
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
/var/log/httpd/error_log
查看实时日志:
tail -f /var/log/httpd/error_log
如果 php.ini 中:
log_errors = On
且未单独指定 error_log,错误会写入 Apache error_log。
php --ini
或:
php -i | grep "Loaded Configuration File"
grep error_log /etc/php.ini
示例:
error_log = /var/log/php_error.log
storage/logs/laravel.log
runtime/log/
# 查看所有 PHP 相关日志
ls -lh /var/log | grep php
# 实时查看日志
tail -f /var/log/php-fpm/error.log
tail -f /var/log/httpd/error_log
| 场景 | 日志位置 |
|---|---|
| PHP-FPM 错误 | /var/log/php-fpm/error.log |
| PHP-FPM 脚本错误 | /var/log/php-fpm/www-error.log |
| Apache + PHP | /var/log/httpd/error_log |
| 自定义 PHP 日志 | 查看 php.ini 中 error_log |
| Nginx 错误 | /var/log/nginx/error.log |
如果你愿意,可以告诉我:
我可以帮你 精确定位到具体文件。