PHP 的配置设置“error_log”不工作

发布于 2024-08-09 23:16:10 字数 4468 浏览 7 评论 0 原文

我在这里做错了什么?

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

What am I doing wrong here?

I have error_log set in the .ini file along with error_reporting = E_ALL | E_STRICT.

What else am I missing? This usually gave it to me. I want this set in the .ini file and not in my scripts.

Another interesting thing that is happening is that when I purposefully try and throw an error in one of my scripts, Apache restarts over and over again.


This is my event log after one error. Look at the timestamp.

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.

This has been asked 1000 times and I have browsed through the different posts before posting this, but I have not found an answer. As long as I have been programming with PHP, this have always been a nightmare to get working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

横笛休吹塞上声 2024-08-16 23:16:10

检查 PHP-FPM 是否未显式设置 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

然后重新启动 php-fpm:

systemctl restart php-fpm

检查 Apache .htaccess 文件是否使用

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

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

Check PHP-FPM is not explicitly setting error_log:

Make sure the file /etc/php-fpm.d/www.conf does not contain php_admin_value settings for error_log. Search for the following and comment them out using a semi-colon:

; 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

Then restart php-fpm:

systemctl restart php-fpm

Check Apache .htaccess files are not setting the error_log value using

php_admin_value settings in the Apache configuration files cannot be overridden, so make sure you don’t have any php_admin_value for the error_log setting in the Apache configuration files. Also check for php_value settings just in case.

PHP Website - How to change configuration settings

萌无敌 2024-08-16 23:16:10

Flimm 的故障排除指南

这是我的故障排除指南 error_log()< /code> 调用不起作用。

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


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

  3. 检查.ini文件中的PHP配置。具体来说,检查 log_errors = Onerror_reporting = E_ALLerror_log = /var/log/apache2/php_errors.log (请参阅文档 < a href="http://php.net/manual/en/errorfunc.configuration.php#ini.log-errors" rel="nofollow noreferrer">log_errors, error_reportingerror_log 配置设置)。要查找 .ini 文件,请查看 phpinfo(); 的输出。如果未设置 error_log,则默认情况下它将转到服务器的错误日志,如前面的步骤所述。如果 error_log 设置为文件,则它应该已经存在并且可写,就像前面的步骤一样。配置更改后请记住重新启动服务器。

  4. 检查服务器配置没有更改 PHP 设置。您的服务器配置(甚至.htaccess)可以更改 PHP 配置设置。在 Apache 中,这是使用 php_admin_valuephp_admin_flag 完成的 (文档)。例如,您可能会在 .htaccess 文件中找到以下行:php_admin_flag[log_errors] = off。配置更改后请记住重新启动服务器。

  5. 检查 AppArmor 是否会导致权限问题。 (AppArmor 通常安装在 Debian、Ubuntu 和类似发行版中。)要检查 AppArmor 是否已启用,请运行 aa-enabled 。通过在 sudo Journalctl 的输出或文件 /var/log/kern.log 或类似文件中搜索 apparmor 查找错误消息。您可以使用 aa-notify 获取 AppArmor DENIED 消息的桌面通知。请参阅 AppArmor 文档

  6. 检查SELinux是否不会导致权限问题。 (SELinux 通常安装在 RHEL、Fedora 和类似发行版上。)要检查 SELinux 是否已启用,请运行 sudo sestatus 。有关更多详细信息,请参阅此答案

此时,您应该能够创建一个测试文件 test.php,其内容为 ,重新启动服务器,然后在浏览器中打开 URL,您应该能够在错误日志(服务器的或由 error_log = 指定的日志)中看到 test。但请继续阅读。

  1. 检查PHP 的设置在运行时没有更改log_errors 选项可以在运行时通过运行 ini_set('log_errors', 1); 进行更改,其他配置选项 error_reporting错误日志。另请注意,有一个特殊的 error_reporting() PHP 函数 在运行时更改配置。在代码库中搜索 ini_seterror_reporting 的任何调用。例如,WordPress 确实根据 WP_DEBUG 的值来运行这些。

其他需要注意的事项:

  • 如果您使用 Xdebug,则可以使用设置 xdebug.force_error_reporting 要启用错误报告,请设置为以下值:xdebug.force_error_reporting = 2147483647
  • error_log(); 可能需要几秒钟的时间才能将写入刷新到日志文件。

Flimm's Troubleshooting Guide

Here is my troubleshooting guide to error_log() calls not working.

  1. Look at your server's configuration to find out where the default error log file is. This depends on which server you're using. To get you started, have a look at Apache's ErrorLog and LogLevel options if you're using Apache or Nginx's error_log option if you're using Nginx. Make sure it is set to a file. If you're using a tool like Valet, note that it's using server software like Nginx behind the scenes.

  2. Check the permissions of your server's error log file. On Unix-like systems, it should be writeable by the correct user and group, and the permissions of the parent directory and all its ancestors need to be correct as well. Use chmod and chown. On Debian and Ubuntu, the files and directories need to be have the user or group set to www-data.

  3. Check the configuration of PHP in the .ini files. Specifically, check for log_errors = On and error_reporting = E_ALL and error_log = /var/log/apache2/php_errors.log (see docs for log_errors, error_reporting and error_log configuration settings). To find the .ini file, look at the output of phpinfo();. If error_log is not set, by default it goes to the error log for the server, mentioned in the previous steps. If error_log is set to a file, it should already exist and be writeable, just like in previous steps. Remember to restart the server after configuration changes.

  4. Check that PHP's settings aren't being changed by server configuration. Your server's configuration (even .htaccess) can change PHP configuration settings. In Apache, this is done using php_admin_value and php_admin_flag (docs). For instance, you may find in your .htaccess file this line: php_admin_flag[log_errors] = off. Remember to restart the server after configuration changes.

  5. Check that AppArmor isn't causing permission issues. (AppArmor is usually installed in Debian, Ubuntu and similar distros.) To check if AppArmor is enabled, run aa-enabled . Find error messages by searching for apparmor in the output of sudo journalctl or in the file /var/log/kern.log or similar. You can use aa-notify to get desktop notifications for AppArmor DENIED messages. See AppArmor documentation.

  6. Check that SELinux isn't causing permission issues. (SELinux is usually installed on RHEL, Fedora, and similar distros.) To check if SELinux is enabled, run sudo sestatus . See this answer for more details.

At this point, you should be able to create a test file test.php with the contents <?php error_log("test");, restart your server, and open the URL in your browser, and you should be able to see test in your error log (either the server's, or the one specified by error_log = ). But keep reading.

  1. Check that PHP's settings aren't being changed at run-time. The log_errors option can be changed at runtime by running ini_set('log_errors', 1);, and so can the other configuration options error_reporting and error_log. Also note there is a special error_reporting() PHP function which changes the configuration at run-time. Search your code-base for any invocations of ini_set or error_reporting. WordPress for example does run these depending on the value of WP_DEBUG.

Other things to look at:

  • If you're using Xdebug, you can use the setting xdebug.force_error_reporting to enable error reporting, by setting to this value: xdebug.force_error_reporting = 2147483647
  • It may take a few seconds for error_log(); to flush the write to the log file.
网白 2024-08-16 23:16:10

您还需要设置 log_errors = On< /code> 在文件 php.ini 中。

You also need to set log_errors = On in file php.ini.

尴尬癌患者 2024-08-16 23:16:10

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

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

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

In case anyone else is having trouble getting their local development environment to log errors, here's what fixed it for me:

On Windows, error_log must be set to the complete path to the log for error_log() to work (error_log = c:\apache\php_errors.log). However, if error_log = php_errors.log with no path, php will still be able to log startup errors such as

PHP Startup: Unable to load dynamic library 'ext\php_mysqli.dll' - The specified module could not be found

何以畏孤独 2024-08-16 23:16:10

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

chmod 777 watermellon-app-errors.log

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

The problem I ran into was that the error log I had designated was write-protected. All my .htaccess settings were correct, but PHP just couldn't write to the error log, because it didn't have any permissions. This fixed it right up for me:

chmod 777 watermellon-app-errors.log

Obviously, you're going to want to change the .log part to whatever file you're using for a log.

尹雨沫 2024-08-16 23:16:10

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

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

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

If the error_log directive is set, the file will be used for recording PHP errors. When it is not set, errors will be logged to the Apache log. Take a look at error_log.

The error_log file and the directory it's in must be writable by the user that Apache is running under. If the file isn't being created, it's probably due to a permissions issue.

I don't know for sure why Apache would be crashing on you, but I'm guessing it's a permissions issue of some sort.

伊面 2024-08-16 23:16:10

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

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

在此处输入图像描述

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

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

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

If you are using Fedora, SELinux (enabled by default) will prevent Apache / httpd from appending errors to your log file even when your file is specified in file php.ini and its containing directory has all permissions allowed.

You can see if this is happening by looking at your system log file in /var/log/messages

Enter image description here

The ideal solution is to configure SELinux to allow access to the log file.

The quicker solution is to disable SELinux in /etc/selinux/config by setting SELINUX to disabled.

You'll need to reboot your system after doing this for the change to take effect.

赏烟花じ飞满天 2024-08-16 23:16:10

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

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

I don't understand why, but the error log is now working. Here is what I did.

I gave up and commented back out the error_log directive and closed the ini file. I ran the script with the parse error to see if Apache would still crash and I got the PHP error in the log file. This is freaky, because the ini file no longer has error_log enabled and my script is not using ini_set().

爱已欠费 2024-08-16 23:16:10

就我而言,在 CentOS 开发服务器上,在完整的 yum 更新/var/log/http 的权限更改为 700 并将用户设置为“root”,因此用户“apache”无法输入或写入。

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

发出命令

chown apache /var/log/httpd

解决了问题。

In my case, on a CentOS development server, after a full yum update, the permission on /var/log/http was changed to 700 and the user to 'root', so the user 'apache' wasn't able to enter or write into it.

It was still able to write into the existing file /var/log/httpd/error.log, but it wasn't able to create a new file, as I use date-suffixed log files.

Issuing the command

chown apache /var/log/httpd

solved the problem.

伴我老 2024-08-16 23:16:10

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

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

    log_errors = 开
    error_log = /var/log/php_error.log
    
  2. Restart Apache

    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
    
    ;
        <正文>
            PHP 文件:
            
        
    
    
  6. 检查是否写入错误

    sudo less /var/log/php_error.log
    

For me, manually creating the file, /var/log/php_error.log, solved the issue:

  1. In file php.ini, configure log to file

    log_errors = On
    error_log = /var/log/php_error.log
    
  2. Restart Apache

    sudo systemctl restart apache2
    
  3. Create the log file, for example:

    sudo touch /var/log/php_error.log
    
  4. Give the correct rights (owner must be Apache)

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

    (And if not already set)

    sudo chmod 0644 /var/log/php_error.log
    
  5. Test this way, for example:

    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. Check the error is written

    sudo less /var/log/php_error.log
    
捎一片雪花 2024-08-16 23:16:10

为了进一步调试:
phpinfo();

它显示当前的 error_log 设置,位于 phpinfo() 中的 error_log 值旁边,并且在虚拟主机不可用时很有用记录日志。

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

For further debugging:
phpinfo();

It shows the current error_log setting, next to the error_log value in phpinfo() and can be useful when a vhost isn't logging.

I ended up here after that setting got overridden from file php.ini and the vhost. I ended up logging to syslog.

锦欢 2024-08-16 23:16:10

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

As bradym said, check whether you have write permissions to the directory where you PHP error log is located for the Apache user. If you created a log file with written permissions it's not enough; the directory should have them too.

远山浅 2024-08-16 23:16:10

我遇到了同样的问题,并通过这样做修复了它:

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

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

I had the same issue and fixed it by doing this:

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

I think PHP runs as user www-data while access to /var/log/apache2 is limited to root. So, this fixes it.

一城柳絮吹成雪 2024-08-16 23:16:10

error_log = "C:\php\Log\error.log" 行对我来说也不起作用。对我来说,解决方案是您不应该自己创建 error.log,因为 PHP 会为您做这件事。 查看 PHP 留言板。我在 Windows Server 2008 服务器上使用 PHP 5.2。

The error_log = "C:\php\Log\error.log" line was not working for me either. The solution for me was that you shouldn't create the error.log yourself, because PHP will do it for you. See the PHP message board. I'm using PHP 5.2 on a Windows Server 2008 server.

ぽ尐不点ル 2024-08-16 23:16:10

这对我来说很有效。

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 ,但这对我。

This did the trick for me.

setsebool -P httpd_unified 1

Please note, this would be the preferred method below to try first:

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

This answer was derived from the logs from executing this command line:

journalctl -xe

Further information on the system I was running on:

PHP 7.0 and CentOS 7

I am not sure if it's not obvious, but the issue was Apache's configuration to writing files. I did try chmod 777, chmod a+w on the logging directory, but this didn't work for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文