Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable display_errors with .htaccess

Tags:

php

.htaccess

I have the following environment on one server:

  1. dev.domain.com for the development
  2. test.domain.com for the tests
  3. www.domain.com is the working production

For the development environment I would like to see all PHP errors (including parse errors). Unfortunately the PHP configuration is quite strict. It does not allow to set the display_errors within the PHP file. It means that

ini_set("display_errors", 1);

and all variants of it are not working. The following works fine within the .htassess file:

php_flag display_errors "1"

Thus, my idea was to do something like this:

if(HOST==dev.domain.com) {
    php_flag display_errors "1"
}

I tried SetEnvIf, RewriteCond, IfDefine and other variants, but without success.

Is there somehow a way to do it?

like image 481
Dennis Avatar asked Mar 24 '11 03:03

Dennis


People also ask

How can you enable error reporting in PHP?

The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

How do I turn off PHP error reporting?

To turn off or disable error reporting in PHP, set the value to zero. For example, use the code snippet: <? php error_reporting(0); ?>


1 Answers

As I mentioned in my comment, you can set display_errors using ini_set(). However, it won't help with parse errors as noted in the manual

Can you make changes to the VirtualHost sections for each site? If so, add the php_flag in there.

If not, why not just have a different .htaccess file per site?

like image 56
Phil Avatar answered Oct 21 '22 01:10

Phil