34

我在这里做错了什么?

我在 .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 编程,这一直是工作的噩梦。

4

15 回答 15

17

检查 PHP-FPM 没有明确设置error_log

确保该文件/etc/php-fpm.d/www.conf不包含error_logphp_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 配置文件中的设置不能被覆盖,因此请确保您没有任何php_admin_value用于error_logApache 配置文件中的设置。还要检查php_value设置以防万一。

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

于 2016-04-09T08:49:04.383 回答
11

您还需要log_errors = On在文件php.ini中进行设置。

于 2009-11-05T02:54:03.493 回答
9

如果其他人无法让他们的本地开发环境记录错误,这就是为我解决的问题:

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

PHP 启动:无法加载动态库 'ext\php_mysqli.dll' - 找不到指定的模块

于 2012-11-13T22:20:25.800 回答
9

Flimm 的故障排除指南

error_log()这是我的呼叫无法正常工作的故障排除指南。

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

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

  3. 检查文件中 PHP 的配置.ini。具体来说,检查log_errors = Onanderror_reporting = E_ALL | E_STRICTerror_log = /tmp/example/php_errors.log(请参阅和配置设置的文档)log_errors。要查找该文件,请查看. 如果未设置,默认情况下会转到服务器的错误日志,如前面的步骤中所述。如果设置为一个文件,它应该已经存在并且是可写的,就像在前面的步骤中一样。请记住在配置更改后重新启动服务器。error_reportingerror_log.iniphpinfo();error_logerror_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 中遇到权限问题(请参阅此答案)。

于 2018-11-08T11:16:16.600 回答
8

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

chmod 777 watermellon-app-errors.log

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

于 2012-10-08T18:58:19.650 回答
4

如果设置了error_log指令,该文件将用于记录 PHP 错误。如果未设置,错误将记录到 Apache 日志中。看看error_log

error_log 文件及其所在的目录必须可由运行 Apache 的用户写入。如果未创建文件,则可能是由于权限问题。

我不确定为什么 Apache 会在你身上崩溃,但我猜这是某种权限问题。

于 2009-11-18T08:04:23.853 回答
2

就我而言,在CentOS开发服务器上,在 full 之后, /var/log/httpyum update的权限更改为700,用户更改为“root”,因此用户“apache”无法进入或写入它。

它仍然能够写入现有文件/var/log/httpd/error.log,但它无法创建新文件,因为我使用日期后缀的日志文件。

发出命令

chown apache /var/log/httpd

解决了这个问题。

于 2017-09-21T16:40:36.397 回答
1

我不明白为什么,但错误日志现在正在工作。这就是我所做的。

我放弃并注释掉了error_log指令并关闭了 ini 文件。我运行带有解析错误的脚本以查看 Apache 是否仍会崩溃,并且在日志文件中出现 PHP 错误。这很奇怪,因为 ini 文件不再启用error_log并且我的脚本没有使用ini_set()

于 2009-11-05T04:24:45.977 回答
1

如果您使用FedoraSELinux(默认启用)将阻止 Apache / httpd 将错误附加到您的日志文件,即使您的文件在文件php.ini中指定并且其包含目录具有所有允许的权限。

您可以通过查看/var/log/messages中的系统日志文件来查看是否发生这种情况

在此处输入图像描述

理想的解决方案是将 SELinux 配置为允许访问日志文件。

更快的解决方案是通过将SELINUX设置为禁用来禁用/etc/selinux/config中的 SELinux 。

执行此操作后,您需要重新启动系统才能使更改生效。

于 2015-03-23T14:49:42.197 回答
1

对我来说,手动创建文件/var/log/php_error.log解决了这个问题:

  1. 在文件php.ini中,配置日志到文件

    log_errors = On
    error_log = /var/log/php_error.log
    
  2. 重启阿帕奇

    sudo systemctl restart apache2
    
  3. 创建日志文件,例如:

    sudo touch /var/log/php_error.log
    
  4. 赋予正确的权利(所有者必须是 Apache)

    sudo chown www-data:root /var/log/php_error.log
    

    (如果尚未设置)

    sudo chmod 0644 /var/log/php_error.log
    
  5. 以这种方式进行测试,例如:

    sudo vim /var/www/.../index.php
    
    <html>
        <body>
            PHP file:
            <?php
                echo "Hello, World!";
                trigger_error("User error in PHP", E_USER_ERROR);
            ?>
        </body>
    </html>
    
  6. 检查错误是否写入

    sudo less /var/log/php_error.log
    
于 2021-09-16T12:30:48.303 回答
0

正如bradym 所说,检查您是否对 Apache 用户的 PHP 错误日志所在的目录具有写入权限。如果您创建了具有写入权限的日志文件,这还不够;目录也应该有它们。

于 2010-12-10T14:44:45.123 回答
0

error_log = "C:\php\Log\error.log"条线也不适合我。我的解决方案是您不应该自己创建error.log,因为 PHP 会为您完成。请参阅 PHP 留言板。我在Windows Server 2008服务器上使用 PHP 5.2。

于 2011-07-28T08:50:01.480 回答
0

进一步调试: phpinfo();

它在 phpinfo() 中的error_log值旁边显示当前的error_log设置,并且在 vhost 没有记录时很有用。

在该设置被文件php.ini和虚拟主机覆盖后,我最终来到了这里。我最终登录到系统日志。

于 2019-09-03T13:35:51.833 回答
0

我有同样的问题并通过这样做解决了它:

chmod 0777 -R /var/log/apache2
apachectl restart

我认为 PHP 以用户身份运行,www-data而访问权限/var/log/apache2仅限于root. 所以,这解决了它。

于 2020-08-18T07:14:04.513 回答
-1

这对我有用。

setsebool -P httpd_unified 1

请注意,这将是下面首先尝试的首选方法:

semanage fcontext -a -t httpd_sys_rw_content_t 'errorLogNameHere.error.log
restorecon -v 'errorLogNameHere.error.log'

此答案来自执行此命令行的日志:

journalctl -xe

关于我运行的系统的更多信息:

PHP 7.0 和CentOS 7

我不确定这是否不明显,但问题是 Apache 写入文件的配置。我确实在日志目录上尝试了chmod 777, chmod a+w ,但这对我不起作用。

于 2017-11-12T08:59:01.340 回答