Apache 不记录 php 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8209729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache does not log php errors
提问by Justinas Lelys
PHP via CLI successfully logs errors to /var/log/php_errors.log.
PHP 通过 CLI 成功地将错误记录到 /var/log/php_errors.log。
But apache + php does not log errors.
但是 apache + php 不会记录错误。
[bla@notebook ~]$ apachectl -v
Server version: Apache/2.2.17 (Unix)
Server built: May 19 2011 03:15:39
[bla@notebook ~]$ php -v
PHP 5.3.6 with Suhosin-Patch (cli) (built: Mar 23 2011 13:28:00)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
In php.iniI have:
在php.ini我有:
display_errors = On
error_reporting = E_ALL | E_STRICT
log_errors = On
error_log = php_errors.log
In httpd.conf:
在httpd.conf 中:
ErrorLog "/var/log/httpd/error_log"
Permissions:
权限:
[bla@notebook /]$ ls -la /var/log/httpd/
-rwxrwxr-x 1 root root 133351 21.11.2011 11:18 access_log*
-rwxrwxr-x 1 root http 1307 21.11.2011 11:18 error_log*
[bla@notebook /]$ ls -la /var/log/php_errors.log
-rwxrwxr-x 1 root http 521 14.11.2011 17:31 /var/log/php_errors.log*
As you can see the Apache daemon has permissions to write into log files.
如您所见,Apache 守护进程具有写入日志文件的权限。
Still no errors from Apache or PHP in /var/log/php_errors.log and /var/log/httpd/error_log.
在 /var/log/php_errors.log 和 /var/log/httpd/error_log 中仍然没有来自 Apache 或 PHP 的错误。
UPDATE 1.
更新 1。
Changed this line in php.ini:
在 php.ini 中更改了这一行:
error_log = php_errors.log
to full path:
到完整路径:
error_log = /var/log/php_errors.log
Permissions were ok. But if someone is also having problems with it, you can debug setting permissions to logfile 0777 or changing file owner.
权限没问题。但如果有人也遇到问题,您可以调试日志文件 0777 的设置权限或更改文件所有者。
采纳答案by Narf
There are usually two separate php.ini files for Apache and CLI - are you sure you're looking at the correct one?
Apache 和 CLI 通常有两个单独的 php.ini 文件 - 您确定要查看正确的文件吗?
Edit:
编辑:
2 more options that I can think of:
我能想到的另外两个选项:
- some Apache directive is messing with PHP's log path (or disabling the logging options, though that is very unlikely to be the case) - try setting an absolute path to the log file in php.ini (@Frosty Z has suggested something like this)
- I notice that your PHP installation has the Suhosin patch applied, which does several restrictive modifications in order to improve security. And while in theory there are sufficient permissions for a user in the
http
user group to write to the logfile - there's probably some suphp-like behaviour and when your script is accessed through the web it is executed with/as the username that is set as it's owner (file owner of the script that is) - try changing it.
- 某些 Apache 指令正在干扰 PHP 的日志路径(或禁用日志记录选项,尽管这种情况不太可能发生) - 尝试在 php.ini 中设置日志文件的绝对路径(@Frosty Z 提出了类似的建议)
- 我注意到您的 PHP 安装应用了 Suhosin 补丁,它进行了一些限制性修改以提高安全性。虽然理论上
http
用户组中的用户有足够的权限来写入日志文件 - 可能有一些类似 suphp 的行为,当您的脚本通过网络访问时,它会使用/作为设置的用户名执行所有者(即脚本的文件所有者) - 尝试更改它。
回答by Stelian
I had the same problem.
我有同样的问题。
Setting log_errors_max_len = 0
in php.ini worked for me.
log_errors_max_len = 0
php.ini 中的设置对我有用。
Set the maximum length of log_errors in bytes. In error_log information about the source is added. The default is 1024 and 0 allows to not apply any maximum length at all. This length is applied to logged errors, displayed errors and also to $php_errormsg, but not to explicitly called functions such as error_log().
以字节为单位设置 log_errors 的最大长度。在 error_log 中添加了有关源的信息。默认值为 1024,0 允许根本不应用任何最大长度。此长度适用于记录的错误、显示的错误以及 $php_errormsg,但不适用于显式调用的函数,例如 error_log()。
回答by sgnsajgon
In the past, I had no error logs in two cases:
过去,我在两种情况下都没有错误日志:
- The user under which Apache was running had no permissions to modify
php_error_log
file. - Error 500 occurred because of bad configuration of
.htaccess
, for example wrong rewrite module settings. In this situation errors are logged to Apacheerror_log
file.
- 运行 Apache 的用户没有修改
php_error_log
文件的权限。 - 错误 500 是由于错误的配置而发生的
.htaccess
,例如错误的重写模块设置。在这种情况下,错误会记录到 Apacheerror_log
文件中。
回答by Frosty Z
Check which PHP script you are accessing, and how Apache is configured in order to access it.
检查您正在访问哪个 PHP 脚本,以及如何配置 Apache 以访问它。
In some configurations (e.g. Virtual hosts, specific directories...), the error_log file can be set to a different path/name than the default one.
在某些配置中(例如虚拟主机、特定目录...),可以将 error_log 文件设置为与默认路径/名称不同的路径/名称。
I would then suggest to check your Apache config files.
然后我建议检查您的 Apache 配置文件。
回答by Yevgeniy Afanasyev
httpd.conf
is not the only place where Apache config can sit,
httpd.conf
不是唯一可以放置 Apache 配置的地方,
For example:
例如:
if you use secure connection https://
your extra config will prevail and you would need to look for configuration in files like /opt/local/apache2/conf/extra/httpd-ssl.conf
如果您使用安全连接,https://
您的额外配置将占上风,您需要在文件中查找配置,例如 /opt/local/apache2/conf/extra/httpd-ssl.conf
you can find there something like:
你可以在那里找到类似的东西:
ErrorLog "/var/log/apache/ssl_error.log"
And you will see no errors logged in normal log file, but all of them will go to ssl_error.log
您将不会在正常日志文件中看到任何错误记录,但所有错误都会转到 ssl_error.log
回答by Peter D Jones
This can also be caused by Apache's own LogLevel directive, which if set too high will override PHP's logging. However, it does not override PHP's ability to output errors on the page, ie display_error, and also does not affect CLI PHP. Worth looking into if you have that particular set of symptoms.
这也可能是由 Apache 自己的 LogLevel 指令引起的,如果设置得太高将覆盖 PHP 的日志记录。但是,它不会覆盖 PHP 在页面上输出错误的能力,即 display_error,也不会影响 CLI PHP。如果您有那组特定的症状,值得研究。
回答by mathieu
Checking the logpath on the right server helped for me... facepalm
检查正确服务器上的日志路径对我有帮助... facepalm