0

I am running my website on VPS. I can create 1 instance for LAMP. I want to set different settings for error reporting on development server and production server.

Is there any way to define two different settings for development and production in same php.ini file?

I want to set

error_reporting(-1);

for development server, and

error_reporting(0);

for production server.

Ronak Patel
  • 5,083
  • 7
  • 44
  • 122
  • 1
    And how would php know it is a development or production server when reading the ini file? – poncha Feb 18 '14 at 18:09
  • That's what I am trying to figure it out. I know there is a way to do it. But, I don't know how? – Ronak Patel Feb 18 '14 at 18:10
  • You can apply that configuration on **apache** site rather than php.ini... That way you can have two sets of configuration (2 sites) in apache and you basically turn one off and another - on – poncha Feb 18 '14 at 18:11
  • can we create two settings of apache in VPS? – Ronak Patel Feb 18 '14 at 18:12
  • possible duplicate of [How to manage different php.ini settings in production and development?](http://stackoverflow.com/questions/8963003/how-to-manage-different-php-ini-settings-in-production-and-development) – Amal Murali Feb 18 '14 at 18:16
  • VPS is a server.. Virtual Private, but a Server nonetheless ;) And Apache allows multiple sites. – poncha Feb 18 '14 at 18:19

2 Answers2

0

You can't have two sets of configuration inside the same php.ini file. But you can have multiple sites in Apache.

In each of those sites you can configure environment-dependent settings.

For example, in prod.conf:

php_value error_reporting 0

And, in dev.conf:

php_value error_reporing -1

You can also throw in other stuff like display_errors and error_log definitions like that. Then, you switch on prod.conf site on production server, and dev.conf on the development one.

poncha
  • 7,198
  • 1
  • 31
  • 36
0

You can't do this directly in the php.ini. There are a few ways you can accomplish what you want:

  • You could use settings directly in the Apache vhost conf to explicitly set the desired values for that vhost.

  • You could use directives in a .htaccess file, one for your live app and one for your dev app.

  • You could use an environment variable to trigger your app to set the right settings. In the Apache config or .htaccess, set an environment variable like "APP_MODE" to "development" or "production". Then your application code can look for that var and set the reporting accordingly. E.g., if (getenv('APP_MODE') == 'development') { error_reporting(E_ALL); }

  • You could use a framework that does this for you. Zend Framework for example uses a combination of environment variable and ini file.

Community
  • 1
  • 1
Alex Howansky
  • 44,270
  • 7
  • 68
  • 92
  • When I am trying to edit .htaccess file, it's giving me internal server error. I have defined AllowOverride All in httpd.conf file for my project directory. What am I missing? – Ronak Patel Feb 18 '14 at 20:30
  • Perhaps a syntax error or misspelling? What exactly are you putting in the file? Perhaps a permissions error? Make sure the file is readable by the user that Apache runs under. – Alex Howansky Feb 18 '14 at 20:57
  • ` Options All MultiViews AllowOverride All Order allow,deny Allow from ` – Ronak Patel Feb 18 '14 at 21:00
  • and .htaccess file's permission is: 644 – Ronak Patel Feb 18 '14 at 21:01
  • The .htaccess should exist at the top level of the site you want to affect (i.e., the document_root) and contain `php_value error_reporting 0` -- or whatever value you want to set it to. – Alex Howansky Feb 18 '14 at 21:08
  • ERROR LOG says: Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration – Ronak Patel Feb 18 '14 at 21:20