php error_log无效

Jim*_*Jim 26 php error-logging selinux error-log

这已被问过1000次,我在浏览之前浏览了不同的帖子,但没有找到答案.只要我用PHP编写程序,这一直是工作的噩梦.有人可以告诉我这里我做错了什么吗?

我在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.
Run Code Online (Sandbox Code Playgroud)

cha*_*aos 11

你还需要log_errors = On在php.ini中设置.

  • 嗨混乱,谢谢.我已经把它设置为On.我错过了什么吗? (5认同)
  • 只需重新启动服务器。 (3认同)

Mel*_*ams 9

如果其他人在使用本地开发环境记录错误时遇到问题,以下是为我修复的问题:

在Windows上,error_log必须设置为error_log()工作日志的完整路径(error_log = c:\apache\php_errors.log).但是,如果error_log = php_errors.log没有路径,php仍然可以记录启动错误,如

PHP Startup: Unable to load dynamic library 'ext\php_mysqli.dll' - The specified module could not be found
Run Code Online (Sandbox Code Playgroud)


小智 7

我遇到的问题是我指定的错误日志是写保护的.我的所有.htaccess设置都是正确的,PHP无法写入错误日志,因为它没有权限.这为我解决了这个问题:

chmod 777 watermellon-app-errors.log
Run Code Online (Sandbox Code Playgroud)

显然,您将要将.log更改为您用于日志的任何文件.

  • 日志真的需要777吗?不够644? (4认同)

Bas*_*usa 7

检查PHP-FPM没有显式设置error_log

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

; 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
Run Code Online (Sandbox Code Playgroud)

然后重新启动php-fpm:

systemctl restart php-fpm
Run Code Online (Sandbox Code Playgroud)

使用以下命令检查Apache .htaccess文件未设置该error_log

php_admin_valueapache配置文件中的设置不能被覆盖,因此请确保error_logApache配置文件中的设置没有任何php_admin_value 。还要检查php_value设置以防万一。

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

  • 救星!经过几个小时的故障排除后,这为我解决了这个问题。谢谢! (3认同)

Fli*_*imm 7

Flimm 的故障排除指南

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

  1. 查看服务器的配置以找出默认错误日志文件的位置。这取决于您使用的服务器。要开始使用,请查看 Apache 的ErrorLog选项(如果您使用的是 Apache)或 Nginx 的error_log选项(如果您使用的是 Nginx)。确保将其设置为文件。如果您使用的是 Valet 之类的工具,请注意它在幕后使用了 Nginx 之类的服务器软件。

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

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

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

  5. 检查PHP 的设置在运行时没有被更改。该log_errors选项可以在运行时通过运行更改,ini_set('log_errors', 1);其他配置选项error_reportingerror_log. 另请注意,有一个特殊的error_reporting()PHP 函数可以在运行时更改配置。在您的代码库中搜索ini_set或 的任何调用error_reporting。例如,WordPress 确实会根据WP_DEBUG.

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

  • 还有一件事:如果您正在访问 https: 网站,那么您需要查看“ssl_error_log”文件,而不是“error_log”文件。 (2认同)
  • 我的经验是使用 apache。我花了很长时间试图弄清楚为什么没有任何东西被记录到 `error_log` 文件中,然后意识到这一切都将转到 `ssl_error_log`(尽管有些安装将所有内容发送到 `error_log`,无论它是否是 SSL。 (2认同)