Zend Framework Set Application Environment without editing index.php

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

2 thoughts on “Zend Framework Set Application Environment without editing index.php

  1. I realized from the index.php that this should be possible yet none of my Zend books make a mention how to set it up. Wasn’t sure what to Google for so it took me 30 minutes, but finally found it. Thank!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">