Deploying the Zend Framework with Apache Environment Variables

I have recently set up my development environment in a way that mimics my production environment as closely as possible, which is easy even though I develop on Kubuntu and deploy on centOS. For example, I utulize the exact same directory structure and I make use of php.ini file for settings specific to dev, like displaying errors instead of logging them to a file. Additionally, Zend_Config is a nice place to store stuff that may differ, such as displaying placeholders for ads and throwing exceptions in a dev environment.

The one thing I hadn’t worked out, was calling the appropriate section of the config file. In my bootsrap file, I had previously used:
$config = new Zend_Config_Ini(APP_PATH . ‘configs/config.ini’, ‘development’);
I didn’t update the bootstrap very often and when I did, I had to remember to change ‘development’ to ‘production’. I am also running small sites, so a small amount of down time caused by a mess up really doesn’t matter.

But I have started working with rsync to deploy my site out to production, and didn’t want to have to deal with hand editing the bootstrap every time a change was made. Enter Apache Environment Variables, which allow you to set variables in apache that are available to PHP. in my configuration file specific to one of my dev websites, I put in: SetEnv DEV_ENVIRONMENT development, while in the production server I have SetEnv DEV_ENVIRONMENT production. Now my bootstrap file has a config call like:
$environment = getenv(’DEV_ENVIRONMENT’);
$config = new Zend_Config_Ini(APP_PATH . ‘configs/config.ini’, $environment);

Now I don’t have to worry about hand editing my bootstrap when I upload a new copy. I think you can put the SetEnv in an .htaccess file if you can’t access the main apache configuration file. I just have to learn rsync a little better, and then I will have a nice deployment process, combing Zend Studio for Eclipse, subversion and rsync.

Leave a Reply