特定文件夹的错误报告

is there a way to set error_reporting(E_ALL); for a specific directory rather than including it in each file?

I'd like to turn on error reporting for my beta.mysite.com

You can use a .htaccess file in Apache. Just add this line:

php_value error_reporting 6143

Or for old PHP versions:

php_value error_reporting 2047

Note that you can't use the contants (like E_ALL)

From the manual:

Note: PHP Constants outside of PHP

Using PHP Constants outside of PHP, like in httpd.conf, will have no useful meaning so in such cases the integer values are required. And since error levels will be added over time, the maximum value (for E_ALL) will likely change. So in place of E_ALL consider using a larger value to cover all bit fields from now and well into the future, a numeric value like 2147483647.

Use an .htaccess file to set the option.

<IfModule mod_php5.c>
  display_errors 1
</IfModule>

Now, naturally this only works if you are using apache as a module.

If you want to add the configuration option when using CGI, your options going to be limited.

A couple of ideas:

  • Including something in every script.
  • More exotic: Use a rewrite rule which pointed to a known script in the directory which did the usual set_ini style argument, and then included the intended script by checking the path. I'm bad with rewrite rules, but I know this could be done.

Just a quick note: putting PHP instructions into .htaccess works only if PHP is installed as an Apache module. With PHP installed as CGI all you get is a 500 Internal server error.

for CGI mode you must use php.ini to accomplish that