在 CentOS 上开启 PHP 调试日志,通常分为 PHP 错误日志 和 PHP-FPM 日志 两部分。下面按常见场景说明(以 CentOS 7/8 + PHP 7.x/8.x 为例)。
php --ini
常见路径:
/etc/php.ini
/etc/php.d/*.ini
vi /etc/php.ini
确保以下配置开启:
; 显示错误(开发环境)
display_errors = On
; 记录错误
log_errors = On
; 错误日志路径
error_log = /var/log/php_errors.log
; 错误级别(开发建议)
error_reporting = E_ALL
⚠️ 生产环境建议:
display_errors = Off error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
touch /var/log/php_errors.log
chown apache:apache /var/log/php_errors.log
chmod 664 /var/log/php_errors.log
(如果是 nginx + php-fpm,用户可能是 nginx 或 php-fpm)
php-fpm --test
通常路径:
/etc/php-fpm.conf
/etc/php-fpm.d/www.conf
vi /etc/php-fpm.d/www.conf
开启:
catch_workers_output = yes
在 /etc/php-fpm.conf 中:
error_log = /var/log/php-fpm/error.log
log_level = debug
重启 php-fpm:
systemctl restart php-fpm
tail -f /var/log/nginx/error.log
tail -f /var/log/httpd/error_log
如果你想 断点调试(不是只看日志):
yum install php-pecl-xdebug
php.ini 中添加:
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
重启 PHP:
systemctl restart php-fpm
<?php
error_log("PHP debug test");
?>
查看日志:
tail -f /var/log/php_errors.log
如果你能告诉我:
我可以给你更精确的配置。