在 CentOS 上查看 PHP 错误日志,常见位置和方式如下(按使用场景说明):
php.ini 查看日志路径(最准确)php -i | grep "error_log"
或
php --ini
然后查看对应 php.ini 中的配置:
log_errors = On
error_log = /var/log/php/error.log
/var/log/php-fpm/error.log
或
/var/log/php-fpm/www-error.log
查看:
tail -f /var/log/php-fpm/error.log
/var/log/httpd/error_log
查看:
tail -f /var/log/httpd/error_log
Nginx 本身不记录 PHP 错误,PHP 错误通常在:
/var/log/php-fpm/www-error.log
Nginx 访问/错误日志:
/var/log/nginx/error.log
/var/log/nginx/access.log
tail -f /var/log/php-fpm/error.log
或
tail -100 /var/log/php-fpm/error.log
php -i | grep log_errors
如果是 Off,需要开启:
log_errors = On
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
⚠️ 生产环境不建议开启 display_errors
查看 SELinux 状态:
getenforce
如果是 Enforcing,可临时测试:
setenforce 0
或修改日志目录安全上下文。
# 1. 找到日志路径
php -i | grep error_log
# 2. 查看日志
tail -f /var/log/php-fpm/error.log
# 3. 确认 PHP-FPM / Apache 是否重启
systemctl restart php-fpm
systemctl restart httpd # 或 nginx
如果你愿意,可以把 系统版本(CentOS 7/8/Stream) 和 PHP 运行方式(Apache / Nginx + PHP-FPM) 发我,我可以给你一条最准确的命令路径 ✅