在CentOS上分析PHP日志可按以下步骤操作:
/var/log/php-fpm/
,常见文件包括error.log
(错误日志)、access.log
(访问日志),可通过php --ini
查看php.ini
中error_log
配置确认路径。/var/log/httpd/
(Apache)或/var/log/nginx/
(Nginx)目录下。tail -f /path/to/php-error.log
(如tail -f /var/log/php-fpm/error.log
)。grep "error" /path/to/php-error.log
(支持正则表达式)。ls -lh /path/to/php-error.log
(查看大小、时间等)。journalctl -u php-fpm
:查看PHP-FPM的systemd日志(需systemd支持)。logwatch
:自动生成日志报告,安装后运行logwatch --output mail
可发送日志摘要至邮箱。logrotate
管理日志文件,避免单个文件过大,配置文件位于/etc/logrotate.d/
。php.ini
中error_reporting
和log_errors
是否启用,并确保error_log
路径正确,修改后重启PHP服务(systemctl restart php-fpm
)。top
、htop
查看服务器资源占用情况。参考来源: