Programatically Change The Value Of The Environment Variable

A few months back, our friend Ben Scholzen wrote about setting up the environment variable in your Zend Framework powered application.

With the advent of Zend Framework 1.8 and the Zend_Application component the Zend Framework Quick Start guide recommends this setting.

Handling exceptions and errors, using the same code for production, testing and staging are now easier when you define the application environment.

How do you programatically alter the value of this variable? You could write simple scripts to alter the value of the environment variable.

Solution 1: Use sed

sed -i 's/SetEnv APPLICATION_ENV development/SetEnv APPLICATION_ENV production/g' path/to/.htaccesss <path/to/.htAccess

Solution 2 Use PHP


<?php
$contents 
file_get_contents('.htaccess');
$newString str_replace("SetEnv APPLICATION_ENV development""SetEnv APPLICATION_ENV production"$contents);
file_put_contents('.htaccess'$newString);
?>

Using any of the above two snippets of code you can programatically alter the value of the environment variable from 'development' to 'production' and vice versa.

About the author

Sudheer is an entrepreneur and software developer. Get more from Sudheer on Twitter.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.