在 CentOS 系统中,PHP 日志记录级别的设置取决于你使用的 Web 服务器(如 Apache 或 Nginx)以及 PHP 本身的配置。以下是针对 Apache 和 Nginx 的 PHP 日志记录级别设置方法:
在 Apache 中,你需要修改 httpd.conf
或 apache2.conf
文件(取决于你的 CentOS 版本)。找到以下行:
LogLevel alert rewrite:trace3
将 LogLevel
的值更改为你想要的日志记录级别。可选的日志级别包括:alert
, crit
, debug
, emerg
, err
, info
, notice
, warn
。例如,如果你想要更详细的日志记录,可以将其设置为 debug
:
LogLevel debug
保存文件并重启 Apache 服务以使更改生效:
sudo systemctl restart httpd
在 Nginx 中,你需要修改 nginx.conf
文件。找到以下行:
error_log /var/log/nginx/error.log warn;
将 warn
更改为你想要的日志记录级别。可选的日志级别包括:debug
, info
, notice
, warn
, error
, crit
。例如,如果你想要更详细的日志记录,可以将其设置为 debug
:
error_log /var/log/nginx/error.log debug;
此外,还需要修改 PHP-FPM 的配置文件(通常位于 /etc/php-fpm.d/www.conf
或 /etc/php-fpm.conf
),找到以下行:
catch_workers_output = yes
确保此选项已启用,以便将 PHP 错误记录到 Nginx 错误日志中。
保存文件并重启 Nginx 和 PHP-FPM 服务以使更改生效:
sudo systemctl restart nginx
sudo systemctl restart php-fpm
现在,你应该已经成功设置了 CentOS 系统中 PHP 的日志记录级别。请注意,更高的日志记录级别可能会导致更多的磁盘空间使用,因此请根据实际需求进行调整。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>