【问题标题】:PHP Warnings and Notices Showing with display_errors turned on but are not loggingPHP 警告和通知在 display_errors 打开但未记录时显示
【发布时间】:2015-08-02 23:18:38
【问题描述】:

我正在尝试记录所有错误,但由于某种原因我无法让它工作!如果我在我的 .htaccess 中打开 display_errors,那么错误就会在这里和那里弹出。但我不想让它们显示出来,而是希望将它们放在我可以阅读的日志中,这样我的用户就不会看到错误。

我已将这些添加到我的 .htaccess 文件中:

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /path/to/errors.txt
php_value error_reporting 32767
php_value log_errors_max_len 2048

然而errors.log 仍然是空的!我试过重新启动apache,整个服务器,什么都没有。任何帮助将不胜感激。

PHP 版本 - 5.4.39-0+deb7u2

【问题讨论】:

  • 你确定 "/path/to/errors.txt" 可以被运行 apache 的用户写入,例如用户阿帕奇?
  • @Jobst 到底是什么问题!感谢您和 The Humble Rat 指出这一点,也感谢 Humble Rat 如此详细的回复

标签: php apache .htaccess error-handling error-logging


【解决方案1】:

首先请使用 phpinfo() 检查您的默认设置是否被您的 htaccess 覆盖。 phpinfo 将向您显示本地和主值。

【讨论】:

  • 嗨,谢谢你,检查了所有的值,是的,它们正按预期被覆盖
【解决方案2】:

很可能是权限问题导致错误未记录。这是我使用的 sn-p:

ini_set("error_reporting", -1);
ini_set("log_errors", 1);
ini_set("error_log", "/var/www/site/php-error.log");

我假设您使用的是 Linux 发行版,因此一旦您的页面中有代码,使用命令行创建文件:

touch /var/www/site/php-error.log
chmod 644 /var/www/site/php-error.log

然后对于 Ubuntu/Debian 执行以下操作:

chown www-data:www-data /var/www/site/php-error.log

或者对于 Centos/Red Hat:

chown apache:apache /var/www/site/php-error.log

然后您应该会看到正在记录的错误。如果失败,则通过实时查看错误日志然后刷新页面来检查错误日志。要实时查看日志,请执行以下操作:

对于 Ubuntu/Debian:

tail -f /var/log/apache2/error

对于 Centos/Red Hat

tail -f /var/log/httpd/error

【讨论】:

  • 该死的权限!!我忘了检查他们 DOH!谢谢你,它现在工作得很好!
  • @DarylGoode 碰巧发生在我们当中。很高兴我能帮助你。祝你好运!
猜你喜欢
  • 1970-01-01
  • 2012-01-24
  • 2011-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多