在 CentOS 上定位 PHP 错误,一般按下面几个步骤来做:
php --ini
常见路径:
/etc/php.ini/etc/php.d/*.ini查看以下配置:
display_errors = Off ; 生产环境一般关闭
log_errors = On
error_log = /var/log/php/php_error.log
如果 error_log 没设置,错误可能会写到:
/var/log/php-fpm/error.log
/var/log/php-fpm/www-error.log
查看:
tail -f /var/log/php-fpm/www-error.log
/var/log/httpd/error_log
tail -f /var/log/httpd/error_log
Nginx 本身不跑 PHP,PHP 错误在 php-fpm 日志:
/var/log/php-fpm/www-error.log
Nginx 错误:
/var/log/nginx/error.log
tail -f /var/log/php-fpm/www-error.log
或:
tail -f /var/log/httpd/error_log
访问出问题的页面,观察日志输出。
display_errors = On
error_reporting = E_ALL
重启服务:
systemctl restart php-fpm
# 或
systemctl restart httpd
⚠️ 生产环境排完错要改回 Off
如果是 PHP-FPM:
journalctl -u php-fpm -f
Apache:
journalctl -u httpd -f
| 错误现象 | 可能位置 |
|---|---|
| 500 错误 | php-fpm / httpd error_log |
| 空白页 | display_errors 关了,看日志 |
| 超时 | php-fpm slow log |
| 权限问题 | Permission denied 在日志中 |
slowlog = /var/log/php-fpm/www-slow.log
request_slowlog_timeout = 5s
如果你愿意,可以告诉我:
我可以帮你精准定位。