在CentOS上查看PHP錯誤日志,可按以下步驟操作:
定位日志文件
/var/log/php-fpm/
目錄下,文件名可能為error.log
或www-error.log
。/var/log/httpd/error_log
。/var/log/nginx/error.log
。php --ini
查看php.ini
位置,或用grep -r "error_log" /etc/php*
搜索配置文件中的日志路徑。查看日志內容
sudo tail -f /path/to/error.log
(如sudo tail -f /var/log/php-fpm/error.log
)。sudo cat /path/to/error.log
。sudo grep "關鍵字" /path/to/error.log
。其他工具
journalctl -u php-fpm
查看PHP-FPM的systemd日志。vim
)直接打開日志文件分析。注意:部分場景需先安裝PHP-FPM或對應Web服務器,且生產環境中建議關閉display_errors
,僅通過日志記錄錯誤。