views:

300

answers:

4

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

+3  A: 

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.
altCognito
+6  A: 

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.

Greg
+1 for being so dang detailed, but I added in the bit that points to the config, remove if you don't like
altCognito
+1  A: 

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.

djn
Thanks for the tip, I'm on apache but if someone else was reading this; how would you do it under CGI?
dassouki
Right now I'm using per-directory php.ini files at my shared Linux host. Up to now I've been unable to have the same thing working on my home-based WIndows test server: I believe it requires phpsuexec or suphp running on Apache.If nothing else works I'd resort to include() or auto_prepend a php file with a list of ini_set() instructions at the start of every file...
djn
A: 

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