在 CentOS 上排查 PHP 日志,通常可以从 PHP 自身错误日志、Web 服务器(Nginx/Apache)日志、PHP-FPM 日志 三个方向入手。下面按实战步骤说明。
php --ini
或(常见路径):
/etc/php.ini
/etc/php.d/*.ini
关键配置项:
display_errors = Off # 生产环境建议 Off
log_errors = On
error_log = /var/log/php/php_errors.log
error_reporting = E_ALL
如果没有 error_log,PHP 会:
修改后重启:
systemctl restart php-fpm
/var/log/php-fpm/error.log
/var/log/php-fpm/www-error.log
查看:
tail -f /var/log/php-fpm/www-error.log
如找不到:
php-fpm -i | grep error_log
Nginx 错误日志:
/var/log/nginx/error.log
Nginx 访问日志:
/var/log/nginx/access.log
常见 PHP 报错现象:
FastCGI sent in stderr: "PHP message: ..."connect() failed (111: Connection refused) while connecting to upstream/var/log/httpd/error_log
/var/log/httpd/access_log
tail -f /var/log/php-fpm/www-error.log
grep -i error /var/log/php-fpm/www-error.log
tail -n 100 /var/log/nginx/error.log
php-fpm 或 nginx error.logdisplay_errors=Off 且无日志display_errors = On
PHP Fatal error: Maximum execution time of 30 seconds exceeded
解决:
max_execution_time = 120
Allowed memory size of 134217728 bytes exhausted
解决:
memory_limit = 256M
# 1. PHP 是否报错
php -l index.php
# 2. PHP 配置
php -i | grep error
# 3. 服务状态
systemctl status php-fpm
systemctl status nginx
# 4. 权限问题
ls -l /var/log/php-fpm/
如果你能告诉我:
我可以帮你精准定位问题。