即使 display_errors = On,PHP 也不显示错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6480425/
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
PHP not displaying errors even though display_errors = On
提问by wowpatrick
I have a Ubuntu server running Apache2 with PHP 5. In the php.ini I set error_reporting = E_ALL | E_STRICT
and error_reporting = E_ALL | E_STRICT
, but PHP is still not displaying error messages. I'm also using Apache virtual hosts.
我有一台运行 Apache2 和 PHP 5 的 Ubuntu 服务器。在 php.ini 中我设置了error_reporting = E_ALL | E_STRICT
和error_reporting = E_ALL | E_STRICT
,但 PHP 仍然没有显示错误消息。我也在使用 Apache 虚拟主机。
Also, what is the most strict error reporting PHP5.3 has to offer? I want my code to as up-to-date and future-proof as possible.
另外,PHP5.3 提供的最严格的错误报告是什么?我希望我的代码尽可能保持最新和面向未来。
回答by Ray
You also need to make sure you have your php.ini
file include the following set or errors will go only to the log that is set by default or specified in the virtual host's configuration.
您还需要确保您的php.ini
文件包含以下设置,否则错误只会出现在默认设置或虚拟主机配置中指定的日志中。
display_errors = On
The php.ini
file is where base settings for all PHP on your server, however these can easily be overridden and altered any place in the PHP code and effect everything following that change. A good check is to add the display_errors
directive to your php.ini
file. If you don't see an error, but one is being logged, insert this at the top of the file causing the error:
该php.ini
文件是服务器上所有 PHP 的基本设置,但是这些可以很容易地被覆盖和更改 PHP 代码中的任何位置,并影响更改后的所有内容。一个好的检查是将display_errors
指令添加到您的php.ini
文件中。如果您没有看到错误,但正在记录一个错误,请将其插入导致错误的文件顶部:
ini_set('display_errors', 1);
error_reporting(E_ALL);
If this works then something earlier in your code is disabling error display.
如果这有效,那么您代码中较早的部分正在禁用错误显示。
回答by vk23
I had the same issue and finally solved it. My mistake was that I tried to change /etc/php5/cli/php.ini, but then I found another php.ini here: /etc/php5/apache2/php.ini, changed display_errors = On, restarted the web-server and it worked!
我有同样的问题,终于解决了。我的错误是我试图更改/etc/php5/cli/php.ini,但后来我在这里找到了另一个 php.ini :/etc/php5/apache2/php.ini,更改了 display_errors = On,重新启动了网络服务器它奏效了!
May be it would be helpful for someone absent-minded like me.
也许这对像我这样心不在焉的人会有帮助。
回答by Bartek Kosa
I had the same problem on my virtual server with Parallels Plesk Panel 10.4.4. The solution was (thanks to Zappa for the idea) setting error_reporting value to 32767 instead of E_ALL. In Plesk: Home > Subscriptions > (Select domain) > Customize > PHP Settings > error_reporting - Enter custom value - 32767
我在使用 Parallels Plesk Panel 10.4.4 的虚拟服务器上遇到了同样的问题。解决方案是(感谢 Zappa 的想法)将 error_reporting 值设置为 32767 而不是 E_ALL。在 Plesk 中:主页 > 订阅 >(选择域)> 自定义 > PHP 设置 > error_reporting - 输入自定义值 - 32767
回答by Tomek
Although this is old post... i had similar situation that gave me headache. Finally, i figured that i was including sub pages in index.php with "@include ..." "@" hides all errors even if display_errors is ON
虽然这是旧帖子......我有类似的情况让我头疼。最后,我想我在 index.php 中包含子页面,“@include ...” “@” 隐藏所有错误,即使 display_errors 为 ON
回答by Tomek
When you update the configuration in the php.ini file, you might have to restart apache. Try running apachectl restart
or apache2ctl restart
, or something like that.
当您更新 php.ini 文件中的配置时,您可能需要重新启动 apache。尝试运行apachectl restart
或apache2ctl restart
,或类似的东西。
Also, in you ini file, make sure you have display_errors = on
, but only in a development environment, never in a production machine.
此外,在您的 ini 文件中,请确保您有display_errors = on
,但仅限于开发环境,而不是生产机器。
Also, the strictest error reporting is exactly what you have cited, E_ALL | E_STRICT
. You can find more information on error levels at the php docs.
此外,最严格的错误报告正是您所引用的,E_ALL | E_STRICT
. 您可以在php docs 中找到有关错误级别的更多信息。
回答by fremsoft
Check the error_reporting
flag, must be E_ALL
, but in some release of Plesk there are quotes ("E_ALL"
) instead of (E_ALL
)
检查error_reporting
标志,必须是E_ALL
,但在某些 Plesk 版本中,有引号 ( "E_ALL"
) 而不是 ( E_ALL
)
I solved this issue deleting the quotes("
) in php.ini
我解决了删除引号( "
) 中的这个问题php.ini
from this:
由此:
error_reporting = "E_ALL"
to this:
对此:
error_reporting = E_ALL
回答by mgutt
I had the same problem but I used ini_set('display_errors', '1');
inside the faulty script itself so it never fires on fatal / syntax errors. Finally I solved it by adding this to my .htaccess:
我遇到了同样的问题,但我ini_set('display_errors', '1');
在错误的脚本内部使用了它,因此它永远不会因致命/语法错误而触发。最后我通过将它添加到我的 .htaccess 来解决它:
php_value auto_prepend_file /usr/www/{YOUR_PATH}/display_errors.php
display_errors.php:
display_errors.php:
<?php
ini_set('display_errors', 1);
error_reporting(-1);
?>
By that I was not forced to change the php.ini
, use it for specific subfolders and could easily disable it again.
这样我就没有被迫更改php.ini
,将它用于特定的子文件夹,并且可以轻松地再次禁用它。
回答by mswd745
I have encountered also the problem. Finally I found the solution. I am using UBUNTU 16.04 LTS.
我也遇到过这个问题。最后我找到了解决方案。我正在使用 UBUNTU 16.04 LTS。
1) Open the /ect/php/7.0/apache2/php.ini
file (under the /etc/php
one might have different version of PHP but apache2/php.ini
will be under the version file), find ERROR HANDLING AND LOGGING
section and set the following value {display_error = On, error_reporting = E_ALL}
.
1)打开/ect/php/7.0/apache2/php.ini
文件(/etc/php
可能有不同版本的PHP但apache2/php.ini
会在版本文件下),找到ERROR HANDLING AND LOGGING
部分并设置以下值{display_error = On, error_reporting = E_ALL}
。
NOTE - Under the QUICK REFERENCE
section also one can find these values directives but don't change there just change in Section I told.
注意 - 在该QUICK REFERENCE
部分下也可以找到这些值指令,但不要在我告诉过的部分中更改。
2) Restart Apache server sudo systemctl restart apache2
2)重启Apache服务器 sudo systemctl restart apache2
回答by Johnz
Make sure the php.ini that you're modifying is on the /etc/php5/apache2 folder, or else it won't have any efect...
确保您正在修改的 php.ini 在 /etc/php5/apache2 文件夹中,否则它不会有任何效果...
回答by kayahr
Just want to add another pitfall here in case someone finds this question with a problem similar to mine.
只是想在这里添加另一个陷阱,以防有人发现这个问题与我的问题类似。
When you are using Chrome (Or Chromium) and PHP triggers an error in PHP code which is located inside of a HTML attribute then Chrome removes the whole HTML element so you can't see the PHP error in your browser.
当您使用 Chrome(或 Chromium)并且 PHP 在位于 HTML 属性内的 PHP 代码中触发错误时,Chrome 会删除整个 HTML 元素,因此您无法在浏览器中看到 PHP 错误。
Here is an example:
下面是一个例子:
<p>
<a href="<?=missingFunc()?>">test</a>
</p>
When calling this code in Chrome you only get a HTML document with the starting <p>
tag. The rest is missing. No error message and no other HTML code after this <p>
. This is nota PHP issue. When you open this page in Firefox then you can see the error message (When viewing the HTML code). So this is a Chrome issue.
在 Chrome 中调用此代码时,您只会获得带有起始<p>
标记的 HTML 文档。其余的都不见了。此后没有错误消息和其他 HTML 代码<p>
。这不是PHP 问题。当您在 Firefox 中打开此页面时,您可以看到错误消息(查看 HTML 代码时)。所以这是一个 Chrome 问题。
Don't know if there is a workaround somewhere. When this happens to you then you have to test the page in Firefox or check the Apache error log.
不知道某处是否有解决方法。当您遇到这种情况时,您必须在 Firefox 中测试页面或检查 Apache 错误日志。