无法启用php display_errors

Mik*_*tes 15 php apache

嘿,我知道有关于这个主题的一些帖子,我已经搜索了所有这些!

无论我做什么,我都不能在php中启用display_errors设置!

我使用安装了apache2的php 5.3的虚拟盒子.我已经尝试了所有我能想到的显示错误,但似乎没有任何效果.

我在我的.htaccess文件中设置了php_flag display_errors,我甚至直接在php.ini文件中启用了它

display_errors = 1
Run Code Online (Sandbox Code Playgroud)

并尝试过

display_errors = On
Run Code Online (Sandbox Code Playgroud)

我正在使用apache站点启用的默认值是否我需要在这里做一些工作?我从未遇到过使用mamp在我的mac上运行php的问题.

任何建议将不胜感激,这让我疯了!

mar*_*rio 64

您也可以在PHP脚本中启用它:

ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
Run Code Online (Sandbox Code Playgroud)

如果这没有帮助,请先尝试快速解决方法:

set_error_handler("var_dump");
Run Code Online (Sandbox Code Playgroud)

可用于复制原始行为,如果它被某些其他情况所抑制.

请记住,这仅适用于启用运行时错误.如果您怀疑解析错误,您肯定必须在php.ini/.htaccess/.user.ini中启用错误显示.- 否则test.php使用上面的说明创建一个包装器脚本,然后include()是错误的脚本.

  • 哦,将`var_dump`设置为错误处理程序是一个_great_想法.谢谢! (5认同)

kov*_*ack 9

实际上,php.ini两个地方可以遇到display_errors线路.错误的你可以启用第一个,但它被最后一个覆盖display_errors = Off(这种误导的事情发生在我身上).

文件中首先有块:

;;;;;;;;;;;;;;;;;;;
; Quick Reference ;
;;;;;;;;;;;;;;;;;;;
; The following are all the settings which are different in either the production
; or development versions of the INIs with respect to PHP's default behavior.
; Please see the actual settings later in the document for more details as to why
; we recommend these changes in PHP's behavior.

; display_errors
;   Default Value: On
;   Development Value: On
;   Production Value: Off
Run Code Online (Sandbox Code Playgroud)

并且文件中最后一次出现的情况display_errors要低得多:

; 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
Run Code Online (Sandbox Code Playgroud)

一定要改变最后一次出现display_errors.只需将其设置为display_errors = On,重新启动Apache即可获得所需内容.


tes*_*t30 8

每个display_errors:

虽然display_errors可以在运行时设置(with ini_set()),但如果脚本存在致命错误,则不会产生任何影响.这是因为未执行所需的运行时操作.

因此,如果您正在处理不显示错误的问题,并且您的脚本中可能存在语法错误,则设置错误ini_set将无济于事,这需要更改php.ini

sudo sed -i 's/display_errors = Off/display_errors = On/' /etc/php5/apache2/php.ini
Run Code Online (Sandbox Code Playgroud)