温馨提示×

centos php日志怎么实时看

小樊
36
2026-09-12 00:42:15
栏目: 编程语言

在 CentOS 上实时查看 PHP 日志,常用方法取决于 PHP 运行方式(PHP-FPM / Apache mod_php / CLI) 以及 日志路径配置。


一、先确认 PHP 日志在哪

1. 查看 php.ini 中的日志配置

php --ini

或

php -i | grep error_log

常见配置:

log_errors = On
error_log = /var/log/php/php_errors.log

二、实时查看日志(最常用)

✅ 方法 1:tail -f(最推荐)

tail -f /var/log/php/php_errors.log

如果不知道路径,可先搜一下:

find /var/log -name "*php*"

三、PHP-FPM 场景(CentOS 常见)

1. PHP-FPM 错误日志

tail -f /var/log/php-fpm/error.log

2. 慢日志(slow log)

tail -f /var/log/php-fpm/www-slow.log

3. 查看 PHP-FPM 配置确认路径

grep -R "log" /etc/php-fpm.d/www.conf

常见配置:

php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_value[error_log] = /var/log/php/php_errors.log

四、Apache + PHP(mod_php)

Apache 错误日志(PHP 错误一般在这)

tail -f /var/log/httpd/error_log

五、更方便的高级查看方式

1. 多文件实时查看

tail -f /var/log/php-fpm/error.log /var/log/httpd/error_log

2. 带颜色高亮(推荐)

tail -f /var/log/php/php_errors.log | ccze

安装:

yum install ccze -y

3. 只看错误(过滤)

tail -f /var/log/php/php_errors.log | grep -i error

六、如果“完全看不到日志”

检查:

ls -l /var/log/php/
ps aux | grep php-fpm
setenforce 0   # 临时关闭 SELinux 测试

并确认:

  • log_errors = On
  • 日志文件有写权限
  • PHP-FPM / Apache 已重启

如果你愿意,可以告诉我:

  • CentOS 版本(7 / 8 / Stream)
  • PHP 运行方式(FPM / Apache / Nginx)
  • 用的框架(Laravel / ThinkPHP / 原生)

我可以给你精确的日志路径和命令。

0 踩