在 CentOS 上排查 PHP 问题,核心就是看日志 + 定位配置 + 复现错误。下面按常见场景给你一套实用排查思路。
不同方式,日志位置完全不同:
php -v
which php
ps aux | grep php
常见三种:
# 查看 fpm 配置
php-fpm -t
一般路径:
/var/log/php-fpm/error.log
/var/log/php-fpm/www-error.log
查看:
tail -f /var/log/php-fpm/error.log
php --ini
检查:
log_errors = On
error_log = /var/log/php/php-error.log
如果没有设置,错误可能:
Nginx 错误日志:
tail -f /var/log/nginx/error.log
访问日志:
tail -f /var/log/nginx/access.log
典型错误:
FastCGI sent in stderr: "PHP message: ..."connect() failed (111: Connection refused)Primary script unknowntail -f /var/log/httpd/error_log
display_errors = On
error_reporting = E_ALL
log_errors = On
重启:
systemctl restart php-fpm
# 或
systemctl restart httpd
ini_set('display_errors', 1);
error_reporting(E_ALL);
tail -f /var/log/php-fpm/error.log
tail -f /var/log/nginx/error.log
常见原因:
日志示例:
PHP Fatal error: Allowed memory size exhausted
解决:
memory_limit = 256M
Maximum execution time of 30 seconds exceeded
max_execution_time = 120
ls -l /var/log/php
确保 php-fpm 用户(如 apache / nginx)有写权限。
php -m
php -i | grep extension
# 实时看错误
tail -f /var/log/php-fpm/error.log
# 测试 PHP 配置
php -t
php-fpm -t
# 查看 PHP 错误配置
php -i | grep error
display_errors = Onlog_errors如果你愿意,可以告诉我:
我可以直接帮你精确定位。