PHP.ini display_errors 关闭但错误仍然输出到浏览器

PHP.ini display_errors 关闭但错误仍然输出到浏览器

我在其中一个 Web 服务器上遇到一个问题,其中 /etc/php5/apache2/php.ini 中的 php.ini 文件中的 display_errors 设置为 off:

; This directive controls whether or not and where PHP will output errors,
; notices and warnings too. Error output is very useful during development, but
; it could be very dangerous in production environments. Depending on the code
; which is triggering the error, sensitive information could potentially leak
; out of your application such as database usernames and passwords or worse.
; It's recommended that errors be logged on production servers rather than
; having the errors sent to STDOUT.
; Possible Values:
;   Off = Do not display any errors
;   stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
;   On or stdout = Display errors to STDOUT
; Default Value: On
; Development Value: On
; Production Value: Off
; http://php.net/display-errors
display_errors = Off

在文件的上方,这个值被注释掉了。

但是错误和警告仍然显示在网页上。

phpinfo(); 显示 display_errors 已设置为开启,但我不明白它从哪里获取此值。我猜它一定是从某个地方被覆盖了。

另外,如果我更改 php.ini 中的其他选项,那么这些选项会反映在 phpinfo 中,但由于某种原因,它似乎忽略了 display_errors。

任何帮助,将不胜感激。

谢谢罗宾

答案1

经过几个小时查看配置文件后,我现在已经设法解决了这个问题。

事实证明我在 /etc/apache2/conf-enabled/ 中的 phpmyadmin.conf 中有以下代码:

<IfModule mod_php5.c>
    php_admin_flag engine on
    php_admin_value display_errors on
    php_admin_value error_reporting 30711
    php_admin_flag ini_set on
</IfModule>

这将覆盖所有网站的 php.ini。

一旦我删除此代码,它就会从 php.ini 中获取值。

发布此信息以防其他人也遇到这种情况,因为这与其他地方发布的此问题的解决方案不同,后者主要是由于编辑了注释掉的 display_errors 版本或错误的 php.ini 文件,但这里的情况并非如此。

答案2

我遇到了同样的问题,但就我而言,是因为在“Wordpress”中有一个名为“wp-config”的文件,我忘记在“WP_DEBUG”和“WP_DEBUG_LOG”中将其设置为“off”。

相关内容