温馨提示×

centos php日志存放在哪

小樊
41
2026-09-06 06:11:36
栏目: 编程语言

在 CentOS 上,PHP 日志的位置取决于 PHP 的运行方式(PHP-FPM / Apache mod_php / CLI)以及 php.ini 的配置。下面按常见情况说明:


一、PHP-FPM(最常见,Nginx + PHP-FPM)

1. PHP-FPM 错误日志

一般在:

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

或

/var/log/php-fpm/www-error.log

查看 php-fpm 配置确认:

grep error_log /etc/php-fpm.conf
grep error_log /etc/php-fpm.d/www.conf

二、Apache + mod_php

PHP 错误通常会写入 Apache 错误日志:

/var/log/httpd/error_log

或

/var/log/apache2/error_log   # 少数情况

三、PHP 自身错误日志(php.ini 配置)

查看 php.ini 中的 error_log:

php --ini
grep error_log /etc/php.ini

常见情况:

  • 未配置 error_log → 错误写入 Web 服务器日志
  • 已配置,例如:
error_log = /var/log/php_errors.log

则日志在该文件


四、PHP CLI 模式日志

CLI 模式通常:

  • 直接输出到终端
  • 或写入 error_log 指定的文件

查看:

php -i | grep error_log

五、快速排查命令

# 查看 php 错误日志位置
php -i | grep error_log

# 实时查看日志
tail -f /var/log/php-fpm/error.log
tail -f /var/log/httpd/error_log

如果你能告诉我:

  • CentOS 版本(7 / 8 / Stream)
  • Web 服务(Nginx / Apache)
  • PHP 运行方式(PHP-FPM / mod_php)

我可以给你精确到文件的答案。

0 踩