views:

96

answers:

3

I have been developing an application locally with an application environment setting of development. I think this is being set in the .htaccess file.

Then, I have been deploying new versions to the production server.

I don't want to have to manually change the application environment, by hand, every time I deploy a new version.

How should I do this, so I can set the application environment variable automatically (maybe based on the location that it's being hosted? i.e. myapp.com vs. myapp.local)?

+3  A: 
    if (false !== stripos($_SERVER['HTTP_HOST'], 'yourdomain.tld')) {
        $_ENV['APPLICATION_ENV'] = $_SERVER['APPLICATION_ENV'] = 'production';
    }

at the top of index.php

SM
+4  A: 

You can do this in the either in the server config, virtual host, directory or .htaccess through

 SetEnv SPECIAL_PATH /foo/bin

Ex.

<VirtualHost host1>
SetEnv FOO bar1
...
</VirtualHost>
<VirtualHost host2>
SetEnv FOO bar2
...
</VirtualHost>

For more readings

http://httpd.apache.org/docs/1.3/mod/mod_env.html#setenv

http://docstore.mik.ua/orelly/linux/apache/ch04_06.htm

Mark Basmayor
+1 I think this is the right way to do.
Luiz Damim
at hostings you dont have access to apache config filesas of me - i'm using GIT with *.hataccess in .gitignore
SM
A: 

I do something like SM, but slight different:

$env = 'development';

if ('www.my-host-name.com' == $_SERVER['HTTP_HOST'] || 'my-server-name' == exec('hostname')) {
    $env = 'production';
}

defined('APPLICATION_ENVIRONMENT') or define('APPLICATION_ENVIRONMENT', $env);
unset($env);

I use my server hostname to determine the environment. I also use my server name because some scripts are run from a cron job and I need this to do the tests.

Luiz Damim