Question

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.

No correct solution

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top