PHP 显示 display_errors 的警告和通知已打开但未记录
PHP Warnings and Notices Showing with display_errors turned on but are not logging
我正在尝试记录所有错误,但由于某种原因我无法让它工作!如果我在我的 .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
首先请使用 phpinfo() 检查您的默认设置是否被您的 htaccess 覆盖。 phpinfo 将显示本地值和主值。
关于为什么没有记录错误,很可能是权限问题。这是我使用的片段:
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 帽子:
chown apache:apache /var/www/site/php-error.log
然后您应该会看到记录的错误。如果失败,则通过实时查看错误日志并刷新页面来检查错误日志。要实时查看日志,请执行以下操作:
对于Ubunut/Debian:
tail -f /var/log/apache2/error
对于Centos/Red帽子
tail -f /var/log/httpd/error
我正在尝试记录所有错误,但由于某种原因我无法让它工作!如果我在我的 .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
首先请使用 phpinfo() 检查您的默认设置是否被您的 htaccess 覆盖。 phpinfo 将显示本地值和主值。
关于为什么没有记录错误,很可能是权限问题。这是我使用的片段:
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 帽子:
chown apache:apache /var/www/site/php-error.log
然后您应该会看到记录的错误。如果失败,则通过实时查看错误日志并刷新页面来检查错误日志。要实时查看日志,请执行以下操作:
对于Ubunut/Debian:
tail -f /var/log/apache2/error
对于Centos/Red帽子
tail -f /var/log/httpd/error