It is often necessary to differentiate different environments by setting an environment variable with a different value on each of your different systems (development, qa, production). This is very easy to achieve if you are using Apache and PHP. You just need to modify your virtual host definition (See: Creating local virtual hosts with apache) to include a SetEnv directive:

1
2
3
4
5
6
7
8
9
10
11
12
<VirtualHost *:80>
    ServerName ncona.dev
    ServerAlias www.ncona.dev
    SetEnv APPLICATION_ENV development
    DocumentRoot /home/adrian/www/ncona.dev
    <Directory /home/adrian/www/ncona.dev>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

Now you have access to the environment variable from php:

1
getenv('APPLICATION_ENV');
[ apache  php  programming  ]
SSL termination on load-balanced wordpress
Mixins functionality in PHP 5.4 – Traits
Git hook to run code static analysis
Zend Framework Authorization
Creating your own PHPCS standard