Zend Framework Set Application Environment without editing index.php

by antbrown on September 7, 2009

Instead of manually changing the line in index.php to ‘development’ or ‘production’ every time you upload, or commit your changes to repository you can easily set the APPLICATION_ENV using Apache on your local development machine, and leave index.php to default to ‘production’ meaning you no longer have to modify index.php

I use MAMP Pro for local development on my Mac so it was as simple as:

  1. Open MAMP Pro and go to File -> Edit Template -> Apache httpd.conf
  2. Add the following line to the bottom of the file, click save and restart the servers
SetEnv APPLICATION_ENV development

This works because the Zend Framework application checks to see if the Environment Variable has already been set, and if it has it leaves it alone:

defined(’APPLICATION_ENV’) || define(’APPLICATION_ENV’, (getenv(’APPLICATION_ENV’) ? getenv(’APPLICATION_ENV’) : ‘production’));

You don’t need to do this on your server because your application will default to the production environment

Leave a Comment

Previous post: Ant Bitter hits the tanks

Next post: Zend Framework Blogs to Follow