即使 display_errors = On,PHP 也不显示错误

发布于 2024-11-17 07:36:01 字数 230 浏览 2 评论 0原文

我有一个运行 Apache2 和 PHP 5 的 Ubuntu 服务器。在 php.ini 中,我设置了 display_errors = Onerror_reporting = E_ALL | E_STRICT,但 PHP 仍然不显示错误消息。我也在使用 Apache 虚拟主机。

另外,PHP5.3 提供的最严格的错误报告是什么?我希望我的代码尽可能保持最新且面向未来。

I have a Ubuntu server running Apache2 with PHP 5. In the php.ini I set display_errors = On and error_reporting = E_ALL | E_STRICT, but PHP is still not displaying error messages. I'm also using Apache virtual hosts.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

南冥有猫 2024-11-24 07:36:01

您还需要确保您的 php.ini 文件包含以下设置,否则错误将仅发送到默认设置或虚拟主机配置中指定的日志。

display_errors = On

php.ini 文件是服务器上所有 PHP 的基本设置,但是这些设置可以很容易地被覆盖和更改 PHP 代码中的任何位置,并影响更改后的所有内容。一个好的检查方法是将 display_errors 指令添加到 php.ini 文件中。如果您没有看到错误,但正在记录错误,请将其插入到导致错误的文件顶部:

ini_set('display_errors', 1);
error_reporting(E_ALL);

如果这有效,则代码中较早的部分将禁用错误显示。

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.

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:

ini_set('display_errors', 1);
error_reporting(E_ALL);

If this works then something earlier in your code is disabling error display.

纵山崖 2024-11-24 07:36:01

我有同样的问题并最终解决了。我的错误是我尝试更改 /etc/php5/cli/php.ini,但后来我在这里找到了另一个 php.ini: /etc/php5/apache2/php.ini< /em>,更改 display_errors = On,重新启动网络服务器,它起作用了!

也许对于像我这样心不在焉的人会有帮助。

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!

May be it would be helpful for someone absent-minded like me.

故笙诉离歌 2024-11-24 07:36:01

我在使用 Parallels Plesk Panel 10.4.4 的虚拟服务器上遇到了同样的问题。解决方案是(感谢 Zappa 的想法)将 error_reporting 值设置为 32767 而不是 E_ALL。
在 Plesk 中:
首页>订阅数> (选择域名)>定制> PHP设置> error_reporting - 输入自定义值 - 32767

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

思念满溢 2024-11-24 07:36:01

当您更新 php.ini 文件中的配置时,您可能必须重新启动 apache。尝试运行 apachectl restart 或 apache2ctl restart 或类似的东西。

另外,在你的 ini 文件中,确保你有 display_errors = on,但仅在开发环境中,绝不在生产机器中。

此外,最严格的错误报告正是您所引用的,E_ALL | E_STRICT。您可以在php 文档中找到有关错误级别的更多信息。

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.

Also, in you ini file, make sure you have display_errors = on, but only in a development environment, never in a production machine.

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.

断桥再见 2024-11-24 07:36:01

检查 error_reporting 标志,必须是 E_ALL,但在 Plesk 的某些版本中,有引号 ("E_ALL") 而不是 (E_ALL

我解决了这个问题删除引号)在php.ini

从这个:

error_reporting = "E_ALL"

到这个:

error_reporting = E_ALL

Check the error_reporting flag, must be E_ALL, but in some release of Plesk there are quotes ("E_ALL") instead of (E_ALL)

I solved this issue deleting the quotes (") in php.ini

from this:

error_reporting = "E_ALL"

to this:

error_reporting = E_ALL
一袭白衣梦中忆 2024-11-24 07:36:01

虽然这是旧帖...
我也遇到过类似的情况,让我很头疼。
最后,我发现我在index.php中包含了带有“@include ...”的子页面
即使 display_errors 为 ON,“@”也会隐藏所有错误

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

哆啦不做梦 2024-11-24 07:36:01

确保您要修改的 php.ini 位于 /etc/php5/apache2 文件夹中,否则不会有任何效果...

Make sure the php.ini that you're modifying is on the /etc/php5/apache2 folder, or else it won't have any efect...

故事↓在人 2024-11-24 07:36:01

只是想在这里添加另一个陷阱,以防有人发现这个问题与我的问题类似。

当您使用 Chrome(或 Chromium)并且 PHP 触发位于 HTML 属性内部的 PHP 代码中的错误时,Chrome 会删除整个 HTML 元素,以便您在浏览器中看不到 PHP 错误。

下面是一个示例:

<p>
  <a href="<?=missingFunc()?>">test</a>
</p>

在 Chrome 中调用此代码时,您只会获得一个以

标记开头的 HTML 文档。其余的不见了。此

之后没有错误消息,也没有其他 HTML 代码。这不是 PHP 问题。当您在 Firefox 中打开此页面时,您可以看到错误消息(查看 HTML 代码时)。所以这是一个 Chrome 问题。

不知道某处是否有解决方法。当这种情况发生在您身上时,您必须在 Firefox 中测试该页面或检查 Apache 错误日志。

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.

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 not a 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.

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.

十年九夏 2024-11-24 07:36:01

我遇到了同样的问题,但我在错误脚本本身中使用了 ini_set('display_errors', '1'); ,因此它永远不会因致命/语法错误而触发。最后,我通过将其添加到我的 .htaccess 中解决了这个问题:

php_value auto_prepend_file /usr/www/{YOUR_PATH}/display_errors.php

display_errors.php:

<?php
ini_set('display_errors', 1);
error_reporting(-1);
?>

这样我就不必被迫更改 php.ini,将其用于特定的子文件夹,并且可以轻松地再次禁用它。

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:

php_value auto_prepend_file /usr/www/{YOUR_PATH}/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.

安静被遗忘 2024-11-24 07:36:01

我知道这个线程很旧,但我刚刚解决了我的 Ubuntu 服务器的类似问题,我想我会在这里添加一个注释来帮助其他人,因为这个线程是 Google 中关于 PHP 不显示错误主题的第一页。

我在 php.ini 中尝试了几种 error_reporting 值的配置设置。来自 E_ALL | E_STRICT 至 E_ALL & E_NOTICE,但没有一个起作用。我没有在浏览器中显示任何语法错误(这在开发服务器上相当烦人)。将 error_reporting 设置更改为“E_ALL”后,一切都开始工作。不确定这是否是 Ubuntu Oneric 特定问题,但重新启动 Apache 后,错误开始显示在服务器所服务的 HTML 页面中。似乎额外的选项使事情变得混乱,并且所有错误报告都停止了。还有其他人。

I know this thread is old but I just solved a similar problem with my Ubuntu server and thought I would add a note here to help others as this thread was first page in Google for the topic of PHP not displaying errors.

I tried several configuration settings for the error_reporting value in php.ini. From E_ALL | E_STRICT to E_ALL & E_NOTICE and none worked. I was not getting any syntax errors displayed in the browser (which is rather annoying on a development server). After changing the error_reporting setting to "E_ALL" it all started working. Not sure if it is an Ubuntu Oneric specific issue but after restarting Apache errors started showing in the HTML pages the server was serving. Seems the extra options confusing things and all error reporting stops. HTH somone else.

迷雾森÷林ヴ 2024-11-24 07:36:01

我刚刚遇到了同样的问题,结果发现我的问题不在 php.ini 文件中,而只是我以普通用户身份启动 apache 服务器。一旦我执行“sudo /etc/init.d/apache2 restart”,我的错误就会显示出来。

I just experienced this same problem and it turned out that my problem was not in the php.ini files, but simply, that I was starting the apache server as a regular user. As soon as i did a "sudo /etc/init.d/apache2 restart", my errors were shown.

执笔绘流年 2024-11-24 07:36:01

我在 Apache 和 PHP 5.5 上也遇到了同样的问题。
在 php.ini 中,我有以下行:

error_reporting E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors Off

而不是以下行:(

error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors=Off

缺少 = 符号)

I had the same problem with Apache and PHP 5.5.
In php.ini, I had the following lines:

error_reporting E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors Off

instead of the following:

error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors=Off

(the =sign was missing)

从此见与不见 2024-11-24 07:36:01

虽然这个线程很旧,但仍然,我觉得我应该从 这个 stackoverflow 答案

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

经过几个小时的努力,这确实拯救了我。我希望这对某人有帮助。

Though this thread is old but still, I feel I should post a good answer from this stackoverflow answer.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

This sure saved me after hours of trying to get things to work. I hope this helps someone.

习惯成性 2024-11-24 07:36:01

当在带有 ISS 的 Windows 上运行 PHP 时,ISS 中需要进行一些配置设置,以防止显示通用默认页面。

1) 双击 FastCGISettings,单击 PHP,然后单击编辑。将 StandardErrorMode 设置为 ReturnStdErrLn500。

StandardErrorMode

2) 进入站点,双击错误页面,单击 500 状态,单击编辑功能设置,将错误响应更改为详细错误,单击确定

更改对详细错误的错误响应

When running PHP on windows with ISS there are some configuration settings in ISS that need to be set to prevent generic default pages from being shown.

1) Double click on FastCGISettings, click on PHP then Edit. Set StandardErrorMode to ReturnStdErrLn500.

StandardErrorMode

2) Go the the site, double click on the Error Pages, click on the 500 status, click Edit Feature Settings, Change Error Responses to Detailed Errors, click ok

Change Error Responses to Detailed Errors

与风相奔跑 2024-11-24 07:36:01

我也遇到过这个问题。最后我找到了解决方案。我使用的是 UBUNTU 16.04 LTS。

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}

注意 - 在QUICK REFERENCE部分下,人们也可以找到这些值指令,但不要更改,只需更改我所告诉的部分即可。

2)重新启动Apache服务器sudo systemctl restart apache2

I have encountered also the problem. Finally I found the solution. I am using 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}.

NOTE - Under the QUICK REFERENCE section also one can find these values directives but don't change there just change in Section I told.

2) Restart Apache server sudo systemctl restart apache2

╰沐子 2024-11-24 07:36:01

对我来说,我通过删除相关文件夹中的 php_errors.txt 文件解决了这个问题。然后,当代码下次运行时,会再次自动创建该文件,并打印这次的错误。

For me I solved it by deleting the file of php_errors.txt in the relative folder. Then the file is created automatically again when the code runs next time, and with the errors printed this time.

昇り龍 2024-11-24 07:36:01

我也面临同样的问题,我的 php.inni 文件中有以下设置

display_errors = On
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT

但 PHP 错误仍然没有显示在网页上。我只是重新启动我的 apache 服务器,这个问题就解决了。

I also face the same issue, I have the following settings in my php.inni file

display_errors = On
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT

But still, PHP errors are not displaying on the webpage. I just restart my apache server and this problem was fixed.

总以为 2024-11-24 07:36:01

我用尽各种办法追这个问题有一段时间了,但没有结果。

最后发现我调用了一个不再定义的函数,因为它被转移到另一个文件中。

这个明显的(并且很难手动找到)错误没有出现在任何地方。

I chased this problem for some time with all means and no result.

In the end it turned out that I called a function which was no longer defined as it was transferred to a different file.

This obvious (and hard to find manually) error did not show up anywhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文