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)
如果其他人在使用本地开发环境记录错误时遇到问题,以下是为我修复的问题:
在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更改为您用于日志的任何文件.
error_log
:确保文件/etc/php-fpm.d/www.conf
不包含php_admin_value
error_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)
error_log
值php_admin_value
apache配置文件中的设置不能被覆盖,因此请确保error_log
Apache配置文件中的设置没有任何php_admin_value 。还要检查php_value
设置以防万一。
这是我的error_log()
呼叫不工作故障排除指南。
查看服务器的配置以找出默认错误日志文件的位置。这取决于您使用的服务器。要开始使用,请查看 Apache 的ErrorLog
选项(如果您使用的是 Apache)或 Nginx 的error_log
选项(如果您使用的是 Nginx)。确保将其设置为文件。如果您使用的是 Valet 之类的工具,请注意它在幕后使用了 Nginx 之类的服务器软件。
检查服务器错误日志文件的权限。在类 Unix 系统上,它应该可由正确的用户和组写入,并且父目录及其所有祖先的权限也需要正确。使用chmod
和chown
。
检查文件中的 PHP 配置.ini
。具体来说,检查log_errors = On
和error_reporting = E_ALL | E_STRICT
和error_log = /tmp/example/php_errors.log
(请参阅文档以了解log_errors
,error_reporting
和error_log
配置设置)。要查找.ini
文件,请查看phpinfo();
. 如果error_log
没有设置,默认情况下它会转到服务器的错误日志,在前面的步骤中提到过。如果error_log
设置为一个文件,它应该已经存在并且是可写的,就像在前面的步骤中一样。请记住在配置更改后重新启动服务器。
检查PHP 的设置没有被服务器配置更改。您服务器的配置(甚至.htaccess
)可以更改 PHP 配置设置。在 Apache 中,这是使用php_admin_value
and php_admin_flag
( docs ) 完成的。例如,您可能会在.htaccess
文件中找到这一行:php_admin_flag[log_errors] = off
. 请记住在配置更改后重新启动服务器。此时,您应该能够创建一个test.php
包含内容的测试文件<?php error_log("test");
,重新启动服务器,并在浏览器中打开 URL,并且您应该能够test
在错误日志中看到(服务器的或由error_log =
)。但继续阅读。
检查PHP 的设置在运行时没有被更改。该log_errors
选项可以在运行时通过运行更改,ini_set('log_errors', 1);
其他配置选项error_reporting
和error_log
. 另请注意,有一个特殊的error_reporting()
PHP 函数可以在运行时更改配置。在您的代码库中搜索ini_set
或 的任何调用error_reporting
。例如,WordPress 确实会根据WP_DEBUG
.
其他需要注意的事项:您可能在 SELinux 中遇到权限问题(请参阅此答案)。