PHP 的配置设置“error_log”不起作用弗利姆故障排除指南

2022-08-30 12:55:22

我在这里做错了什么?

我在.ini文件中设置了error_log以及.error_reporting = E_ALL | E_STRICT

我还错过了什么?这通常给了我。我希望在.ini文件中设置此集,而不是在我的脚本中。

另一件有趣的事情是,当我故意尝试在我的一个脚本中抛出错误时,Apache会一遍又一遍地重新启动。


这是一个错误后的事件日志。查看时间戳。

Wed Nov 04 19:34:23 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:23 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:23 2009] [notice] Parent: Created child process 1700
[Wed Nov 04 19:34:23 2009] [notice] Child 1700: Child process is running
[Wed Nov 04 19:34:23 2009] [notice] Child 3008: Released the start mutex
[Wed Nov 04 19:34:23 2009] [notice] Child 1700: Acquired the start mutex.
[Wed Nov 04 19:34:23 2009] [notice] Child 1700: Starting 64 worker threads.
[Wed Nov 04 19:34:23 2009] [notice] Child 1700: Starting thread to listen on port 80.
[Wed Nov 04 19:34:24 2009] [notice] Child 3008: All worker threads have exited.
[Wed Nov 04 19:34:24 2009] [notice] Child 3008: Child process is exiting
[Wed Nov 04 19:34:53 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:53 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:53 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:53 2009] [notice] Parent: Created child process 3656
[Wed Nov 04 19:34:53 2009] [notice] Child 3656: Child process is running
[Wed Nov 04 19:34:53 2009] [notice] Child 3656: Acquired the start mutex.
[Wed Nov 04 19:34:53 2009] [notice] Child 3656: Starting 64 worker threads.
[Wed Nov 04 19:34:53 2009] [notice] Child 3656: Starting thread to listen on port 80.
[Wed Nov 04 19:34:53 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:54 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:54 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:54 2009] [notice] Parent: Created child process 3980
[Wed Nov 04 19:34:54 2009] [notice] Child 3980: Child process is running
[Wed Nov 04 19:34:54 2009] [notice] Child 3980: Acquired the start mutex.
[Wed Nov 04 19:34:54 2009] [notice] Child 3980: Starting 64 worker threads.
[Wed Nov 04 19:34:54 2009] [notice] Child 3980: Starting thread to listen on port 80.
[Wed Nov 04 19:34:54 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:54 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:54 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:54 2009] [notice] Parent: Created child process 1600
[Wed Nov 04 19:34:54 2009] [notice] Child 1600: Child process is running
[Wed Nov 04 19:34:54 2009] [notice] Child 1600: Acquired the start mutex.
[Wed Nov 04 19:34:54 2009] [notice] Child 1600: Starting 64 worker threads.
[Wed Nov 04 19:34:54 2009] [notice] Child 1600: Starting thread to listen on port 80.
[Wed Nov 04 19:34:55 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:55 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:55 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:55 2009] [notice] Parent: Created child process 1068
[Wed Nov 04 19:34:55 2009] [notice] Child 1068: Child process is running
[Wed Nov 04 19:34:55 2009] [notice] Child 1068: Acquired the start mutex.
[Wed Nov 04 19:34:55 2009] [notice] Child 1068: Starting 64 worker threads.
[Wed Nov 04 19:34:55 2009] [notice] Child 1068: Starting thread to listen on port 80.
[Wed Nov 04 19:34:55 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:55 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:55 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:55 2009] [notice] Parent: Created child process 3220
[Wed Nov 04 19:34:56 2009] [notice] Child 3220: Child process is running
[Wed Nov 04 19:34:56 2009] [notice] Child 3220: Acquired the start mutex.
[Wed Nov 04 19:34:56 2009] [notice] Child 3220: Starting 64 worker threads.
[Wed Nov 04 19:34:56 2009] [notice] Child 3220: Starting thread to listen on port 80.

这个问题已经被问了1000次,在发布之前,我已经浏览了不同的帖子,但我还没有找到答案。只要我一直用PHP编程,这一直是工作的噩梦。


答案 1

检查 PHP-FPM 是否未显式设置:error_log

确保文件不包含error_log设置。搜索以下内容并使用分号将其注释掉:/etc/php-fpm.d/www.confphp_admin_value

; NOTE: If these are set, ini_set('error_log', 'path') will have no effect
; inside your php code, and this will be forced to be the value always.
; php_admin_value[error_log] = /var/log/php-fpm/www-error.log
; php_admin_flag[log_errors] = on

然后重新启动 php-fpm:

systemctl restart php-fpm

检查 Apache .htaccess 文件是否未使用error_log

php_admin_valueApache 配置文件中的设置无法覆盖,因此请确保 Apache 配置文件中的设置没有任何php_admin_value。还要检查设置以防万一。error_logphp_value

PHP 网站 - 如何更改配置设置


答案 2

弗利姆故障排除指南

这是我的呼叫不起作用的故障排除指南。error_log()

  1. 查看服务器的配置,找出默认错误日志文件的位置。这取决于您使用的服务器。为了帮助您入门,如果您使用的是Apache,请查看Apache的ErrorLog选项,如果您使用的是Nginx,请查看Nginx的error_log选项。确保将其设置为文件。如果您使用的是像 Valet 这样的工具,请注意,它在幕后使用像 Nginx 这样的服务器软件。

  2. 检查服务器错误日志文件的权限。在类Unix系统上,它应该可以由正确的用户和组编写,并且父目录及其所有祖先的权限也需要是正确的。使用和 。chmodchown

  3. 检查.ini文件中 PHP 的配置。具体来说,请检查 和 和(有关log_errorserror_reporting和error_log配置设置,请参阅文档)。要查找该文件,请查看 的输出。如果未设置,则默认情况下,它将转到前面的步骤中提到的服务器的错误日志。如果设置为文件,则它应该已经存在并且是可写的,就像前面的步骤一样。请记住在配置更改后重新启动服务器。log_errors = Onerror_reporting = E_ALL | E_STRICTerror_log = /tmp/example/php_errors.log.iniphpinfo();error_logerror_log

  4. 检查 PHP 的设置是否未被服务器配置更改。服务器的配置(甚至)可以更改 PHP 配置设置。在Apache中,这是使用和(docs)完成的。例如,您可能会在文件中找到以下行:。请记住在配置更改后重新启动服务器。此时,您应该能够创建一个包含内容的测试文件,重新启动服务器,并在浏览器中打开URL,并且您应该能够在错误日志(服务器或指定的错误日志)中看到。但请继续阅读。.htaccessphp_admin_valuephp_admin_flag.htaccessphp_admin_flag[log_errors] = offtest.php<?php error_log("test");testerror_log =

  5. 检查 PHP 的设置在运行时是否未更改。该选项可以在运行时通过运行 进行更改,其他配置选项和 也可以更改。另请注意,有一个特殊的error_reporting()PHP函数,它可以在运行时更改配置。在代码库中搜索 或 的任何调用。例如,WordPress确实根据 的值运行这些。log_errorsini_set('log_errors', 1);error_reportingerror_logini_seterror_reportingWP_DEBUG

其他需要注意的事项:您可能在 SELinux 中遇到权限问题(请参阅此答案)。


推荐