zend framework auto switch production staging test .. etc

user284503 picture user284503 · Mar 24, 2010 · Viewed 10.4k times · Source

What do I change to switch from production to staging.. etc.. and where.. Bootstrap ?

Also, Curious if anyone has configured their Zend Framework to automatically switch from production, staging, test.. etc based on Host information..

example..

 if (hostname = 'prodServer') ... blah
 if (hostname = 'testServer') ... blah

I'm new to Zend but I typically configure my projects to automatically switch run environments based on the host information.

thanks

Answer

Cez picture Cez · Mar 26, 2010

Assuming that you are using APPLICATION_ENV as part of Zend_Application, then you could add this in either your .htaccess or main Apache config (assuming Apache is in use - should still be possible with different Web servers too).

For example, in your .htaccess/config (assumes mod_setenv):

SetEnvIf HTTP_HOST abc.example.com APPLICATION_ENV=production
SetEnvIf HTTP_HOST def.example.com APPLICATION_ENV=staging 
SetEnvIf HTTP_HOST ghi.example.com APPLICATION_ENV=development

Then ensure that APPLICATION_ENV is set in index.php by using:

// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

This is added by Zend_Tool if you use it to generate the project.