在 CentOS 上查看 PHP 错误日志的方法如下:
首先,找到你的 PHP 错误日志文件。通常情况下,它位于 /var/log/php-fpm/
或 /var/log/httpd/
目录下。文件名可能是 error_log
或类似的名称。如果你不确定日志文件的位置,可以检查你的 PHP 配置文件(例如 php.ini
或 www.conf
),找到 error_log
配置项。
使用文本编辑器或命令行工具查看错误日志。你可以使用 cat
、tail
、less
等命令来查看日志文件。例如:
查看整个错误日志:
sudo cat /var/log/php-fpm/error_log
实时查看错误日志的最后几行:
sudo tail -f /var/log/php-fpm/error_log
查看错误日志的最后 100 行:
sudo tail -n 100 /var/log/php-fpm/error_log
如果你使用的是 Apache 服务器,你还可以在 Apache 的错误日志中查看 PHP 错误。Apache 的错误日志通常位于 /var/log/httpd/error_log
。使用类似的方法查看日志:
查看整个 Apache 错误日志:
sudo cat /var/log/httpd/error_log
实时查看 Apache 错误日志的最后几行:
sudo tail -f /var/log/httpd/error_log
查看 Apache 错误日志的最后 100 行:
sudo tail -n 100 /var/log/httpd/error_log
通过这些方法,你应该能够找到并查看 CentOS 上的 PHP 错误日志。