PHP日志在CentOS中的存储位置取决于Web服务器类型(Apache/Nginx)及是否使用PHP-FPM,以下是常见场景的具体路径:
/var/log/httpd/error_log(CentOS 7/8)或/var/log/apache2/error_log(部分旧版本)。/var/log/httpd/access_log。/etc/httpd/conf/httpd.conf或/etc/httpd/conf.d/php.conf)中的ErrorLog和CustomLog指令是否被修改。/var/log/nginx/error.log。/var/log/php-fpm/error.log或/run/php-fpm/www-error.log(部分系统使用/var/log/php-fpm/www.log)。/var/log/php-fpm/access.log(需手动配置)。/etc/php-fpm.conf或/etc/php-fpm.d/www.conf)中的error_log和access_log指令。若未使用默认路径,可通过修改php.ini文件(通常位于/etc/php.ini或/etc/php.d/目录下)中的以下指令自定义日志位置:
error_log = /path/to/php_error.log(需确保目录有写入权限,如chown apache:apache /path/to/php_error.log)。CustomLog、Nginx的access_log)实现,php.ini中的access_log指令仅在CGI/FastCGI模式下有效。grep -r "ErrorLog\|CustomLog" /etc/httpd/(Apache)或grep -r "error_log\|access_log" /etc/nginx/(Nginx)查找具体路径。grep -r "error_log\|access_log" /etc/php-fpm.d/ /etc/php-fpm.conf查找PHP-FPM日志路径。info.php文件(<?php phpinfo(); ?>),访问后在“Loaded Configuration File”中查看php.ini路径,再检查其中的error_log指令。注意:若日志文件不存在,可能是未开启日志记录(需设置log_errors = On)或路径无权限。可通过tail -f /path/to/logfile实时查看日志更新。