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)?

4 Answers

Kent Fredric On Best Solutions

In .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 ;'

to let php compute the value for you.

You need

AllowOverride All

in apaches master configuration to enable .htaccess files.

More Reading on this can be found here:

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.

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.


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

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.

Internet Friend On

I don't believe there's a simple answer to this, but I'd certainly want to be proven wrong.

edit: turns out this can be controlled from .htaccess files. Thanks people! :)

You can use error_reporting() http://docs.php.net/manual/en/function.error-reporting.php to switch the setting on a script by script basis, though. If you happen to have a single script which is included every time at /html/beta/usercomponent, this will do the trick.

Twan On

The easiest way would be to control the error reporting from a .htaccess file. But this is assuming you are using Apache and the scripts in /html/beta/usercomponent are called from that directory and not included from elsewhere.


php_value error_reporting [int]

You will have to compose the integer value yourself from the list as described in the error_reporting documentation, since the constants like E_ERROR aren't defined when Apache interprets the .htaccess.

It's a simple bitwise flag, so a value of 12, for example, would be E_WARNING + E_PARSE + E_NOTICE.

farzad On

you could do this by using an Environment variable. this way you can have more choices than just turning Error reporting on/off for a special directory. in your code where ever you wanted to change any behaviour for a specific set of directoris, or running modes, check if a environment variable is set or not. like this:

if ($_ENV['MY_PHP_APP_MODE'] == 'devel') {
  // show errors and debugging info
} elseif ($_ENV['MY_PHP_APP_MODE'] == 'production') {
 // show some cool message to the user so he won't freak out
 // log the errors and send email to the admin

and when you are running your application in your development environment, you can set an env variable in your .htaccess file like this:

 setenv MY_PHP_APP_MODE devel

or when you are in production evn:

 setenv MY_PHP_APP_MODE production

the same technique applies to your situation. in directories where you want to do something special (turn on error reporting) set some env variable and in your code, check for that.