Reputation: 238667
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
)?
Upvotes: 3
Views: 514
Reputation:
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.
Upvotes: 0
Reputation: 2569
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
Upvotes: 4
Reputation: 3021
if (false !== stripos($_SERVER['HTTP_HOST'], 'yourdomain.tld')) {
$_ENV['APPLICATION_ENV'] = $_SERVER['APPLICATION_ENV'] = 'production';
}
at the top of index.php
Upvotes: 3