无法启用 php display_errors
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5911964/
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
Cannot get php display_errors enabled
提问by Mike Waites
Hey i know there are a few posts regarding this topic and i have scoured them all!
嘿,我知道有一些关于这个主题的帖子,我已经把它们都搜索了!
I cannot not enable the display_errors setting in php no matter what i do!!!
无论我做什么,我都无法在 php 中启用 display_errors 设置!!!
Im using virtual box with php 5.3 installed with apache2 running. i have tried everything i can think of to get display errors working but nothing seems to work.
我使用安装了 php 5.3 并运行 apache2 的虚拟框。我已经尝试了所有我能想到的方法来使显示错误正常工作,但似乎没有任何效果。
I have set php_flag display_errors on in my .htaccess file i have even enabled it directly in the php.ini file
我在我的 .htaccess 文件中设置了 php_flag display_errors 我什至直接在 php.ini 文件中启用了它
display_errors = 1
and also tried
也试过了
display_errors = On
I am using the defaults for apache sites-enabled is there something i need to do here to get this to work?? i have never had this problem running php on my mac using mamp.
我正在使用启用 apache 站点的默认值,我需要在这里做些什么才能使其正常工作吗?我从来没有遇到过使用 mamp 在我的 mac 上运行 php 的问题。
Any suggestions would be greatly appreciated this is driving me nuts!
任何建议将不胜感激,这让我发疯!
回答by mario
You can also enable it in your PHP script usually:
您通常也可以在 PHP 脚本中启用它:
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
If that doesn't help, then try a quick workaround first:
如果这没有帮助,请先尝试快速解决方法:
set_error_handler("var_dump");
Could be used to replicate the original behaviour, if it's suppressed by some other circumstance.
如果被其他情况抑制,则可用于复制原始行为。
Take in mind, this only works for enabling runtime errors. If you suspect parse errors, you'll definitely have to enable error display in the php.ini/ .htaccess/ .user.ini. -- Else make a wrapper
test.php
script with above instructions, theninclude()
the faulty script.
请记住,这仅适用于启用运行时错误。如果您怀疑解析错误,您肯定必须在php.ini/ .htaccess/ .user.ini 中启用错误显示。-- 否则
test.php
使用上述说明制作包装脚本,然后include()
是错误的脚本。
回答by kovpack
Actually, in php.ini
there are two places where you can encounter display_errors
line. By mistake you can enable first one, but it is overriden by the last display_errors = Off
(such misleadming thing happened with me).
实际上,php.ini
有两个地方可以遇到display_errors
line。错误地您可以启用第一个,但它被最后一个覆盖display_errors = Off
(这种误导性的事情发生在我身上)。
There is block that goes first in the file:
文件中先有块:
;;;;;;;;;;;;;;;;;;;
; 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
And the last occurance of display_errors
much lower in the file:
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
Be sure to change last occurence of display_errors
. Just set it to display_errors = On
, restart Apacheand you'll get what you need.
请务必更改 的最后一次出现display_errors
。只需将其设置为display_errors = On
,重新启动 Apache即可获得所需内容。
回答by test30
Per display_errors
:
Although
display_errors
may be set at runtime (withini_set()
), it won't have any effect if the script has fatal errors. This is because the desired runtime action does not get executed.
虽然
display_errors
可以在运行时设置(使用ini_set()
),但如果脚本有致命错误,它不会产生任何影响。这是因为未执行所需的运行时操作。
so if you are dealing with problem not displaying errors and you may have syntax errors in your scripts, setting displaying errors by ini_set will not help, this requires changes in php.ini
因此,如果您正在处理不显示错误的问题,并且您的脚本中可能存在语法错误,那么通过 ini_set 设置显示错误将无济于事,这需要在 php.ini 中进行更改
sudo sed -i 's/display_errors = Off/display_errors = On/' /etc/php5/apache2/php.ini
回答by tamasd
Try error_reporting = E_ALL
. Also, are you sure that you are editing the correct php.ini?
试试error_reporting = E_ALL
。另外,您确定您正在编辑正确的 php.ini 吗?
回答by Paolo Stefan
I usually use (in the PHP script I try to debug):
我通常使用(在我尝试调试的 PHP 脚本中):
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
That usually does the job, but if you have a nasty unmatched parenthesis it could not suffice. So if it doesn't still work, it could depend on some PHP buggy code.
这通常可以完成工作,但是如果您有一个令人讨厌的无与伦比的括号,那是不够的。因此,如果它仍然不起作用,则可能取决于某些 PHP 错误代码。
It could even be that you are editing the wrong php.ini: use phpinfo()and search for the parts under "Loaded Configuration File" and "Additional .ini files parsed".
甚至可能是您编辑了错误的 php.ini:使用phpinfo()并搜索“加载的配置文件”和“解析的其他 .ini 文件”下的部分。
P.S. : display_errors = 1
and display_errors = On
in php.ini are equivalent.
PS:display_errors = 1
和display_errors = On
在php.ini中是等价的。
回答by Romain Petit
Please try:
请尝试:
grep "display_errors" /etc/php5/apache2/php.ini
Just to check how many time it appears.
只是为了检查它出现了多少次。
回答by Romain Petit
In my case, what I had to do is
就我而言,我必须做的是
set_error_handler(NULL);
<the code to debug on screen>
restore_error_handler();
I had defined a custom error handler, which entirely bypassed the default PHP error handler. Yet, I did not want to remove my custom error error handler permanently. So, I used set_error_handler(NULL);
to reset the error_handler to its default value. I used restore_error_handler();
to get back my original custom error_handler.
我定义了一个自定义错误处理程序,它完全绕过了默认的 PHP 错误处理程序。然而,我不想永久删除我的自定义错误处理程序。所以,我曾经set_error_handler(NULL);
将 error_handler 重置为其默认值。我曾经 restore_error_handler();
取回我原来的自定义 error_handler。
回答by willsmanley
In my case, I had switched display_errors to On, but I had forgotten to restart Apache afterwards. Hopefully this helps someone!
就我而言,我已将 display_errors 切换为 On,但之后忘记重新启动 Apache。希望这对某人有所帮助!