如何打开仅在子文件夹中的PHP错误显示 [英] How can I turn on PHP errors display on just a subfolder

查看:69
本文介绍了如何打开仅在子文件夹中的PHP错误显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望PHP错误显示/html,但我希望它们显示在/html/beta/usercomponent中.一切都已设置为完全不显示错误.我该如何获取错误,使其仅显示在该文件夹(及其子文件夹)中?

I don't want PHP errors to display /html, but I want them to display in /html/beta/usercomponent. Everything is set up so that errors do not display at all. How can I get errors to just show up in that one folder (and its subfolders)?

推荐答案

.htaccess中:

php_value error_reporting 2147483647

根据文档,此数字应启用所有"错误,无论版本如何,如果您想要更细致的设置,请手动将这些值或运算在一起,或运行

This number, according to documentation should enable 'all' errors irrespective of version, if you want a more granular setting, manually OR the values together, or run

php -r 'echo E_ALL | E_STRICT ;'

让php为您计算价值.

to let php compute the value for you.

您需要

AllowOverride All

修补主配置中的

以启用.htaccess文件.

in apaches master configuration to enable .htaccess files.

有关此内容的更多信息,请参见:

More Reading on this can be found here:

  • Php/Error Reporting Flag
  • Php/Error Reporting values
  • Php/Different Ways of Tuning Settings

通知:如果您使用的是Php-CGI而不是mod_php,则此方法可能无法像宣传的那样工作,并且您将得到的只是内部服务器错误,除了没有其他选择以外,您将没有其他选择.使用

Notice If you are using Php-CGI instead of mod_php, this may not work as advertised, and all you will get is an internal server error, and you will be left without much option other than enabling it either site-wide on a per-script basis with

error_reporting( E_ALL | E_STRICT ); 

错误发生之前

或类似的构造.

or similar constructs before the error occurs.

我的建议是禁用向用户显示错误,并充分利用php的error_log功能.

My advice is to disable displaying errors to the user, and utilize heavily php's error_log feature.

display_errors = 0
error_logging = E_ALL | E_STRICT 
error_log = /var/log/php 

如果您对此过于嘈杂有疑问,这不是您需要选择性地报告错误的迹象,这是有人应该修复代码的迹象.

If you have problems with this being too noisy, this is not a sign you need to just take error reporting off selectively, this is a sign somebody should fix the code.

@Roger

是的,您也可以在apaches配置中的< Directory> 构造中使用它,但是,.htaccess在这种情况下是等效的,并且使其更可移植,尤其是当您有多个有效的结帐副本时相同的代码库,并且您希望将此更改分配给所有代码库.

Yes, you can use it in a <Directory> construct in apaches configuration too, however, the .htaccess in this case is equivalent, and makes it more portable especially if you have multiple working checkout copies of the same codebase and you want to distribute this change to all of them.

如果您有多个虚拟主机,则需要在相应的虚拟主机定义中使用该构造,否则,是

If you have multiple virtual hosts, you'll want the construct in the respective virtual hosts definition, otherwise, yes

  <Directory /path/to/wherever/on/filesystem> 
      <IfModule mod_php5.c>
         php_value error_reporting 214748364
      </IfModule>
  </Directory>

附加的"ifmodule"命令只是一个安全网,因此,如果没有mod_php,则不会出现上述与apache死亡有关的问题.

The Additional "ifmodule" commands are just a safety net so the above problem with apache dying if you don't have mod_php won't occur.

这篇关于如何打开仅在子文件夹中的PHP错误显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆