Debian PHP日志管理可从以下方面入手:
PHP-FPM日志:
/var/log/php-fpm/
,包含access.log
(访问日志)和error.log
(错误日志)。/etc/php/{版本号}/fpm/pool.d/www.conf
,设置access.format
(访问日志格式)和error_log
(错误日志路径)。logrotate
工具配置/etc/logrotate.d/php-fpm
,设置轮转周期(如每日)、保留天数等。Web服务器日志:
/var/log/apache2/
,通过修改/etc/apache2/apache2.conf
或虚拟主机配置调整ErrorLog
和CustomLog
路径及格式。/var/log/nginx/
,编辑/etc/nginx/nginx.conf
或服务器块配置access_log
和error_log
。PHP脚本日志:
error_log()
函数将自定义日志写入指定文件,如error_log("消息", 3, "/path/to/custom.log")
。Monolog
库实现高级日志管理,支持文件、syslog等多种处理器及轮转策略。日志查看与分析:
tail -f /var/log/php-fpm/error.log
。grep "ERROR" /var/log/php-fpm/error.log
。