Reputation: 4171
Hey I'm trying to launch Magento on EngineYard. Everything works fine except I'm trying to find a way to determine which environment you are currently in and setting dynamic database config for it.
Basically something like this:
if($_SERVER['PHP_ENV' == 'development'){
// Use a different database config
}
This is pretty trivial in other frameworks like Cakephp, Yii, etc but I couldn't find anything specific on how to do this for Magento.
Can anyone point me in the right direction for to get this working? Just trying to save from having to switch the db connection variables back and forth.
Upvotes: 0
Views: 194
Reputation: 8187
Devato, I set up my environments on the server, and it works great.
For instance, if you on APACHE:
<VirtualHost *:80>
....
<Directory "/your_path_root/">
SetEnv APPLICATION_ENV "development"
...
</Directory>
</VirtualHost>
Or in case you on Nginx (e.g. /etc/nginx/sites-available/my_website.conf):
location ~ \.php$ {
...
fastcgi_param APPLICATION_ENV development;
...
}
And then in your application you can check this way:
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
And then on you have the constant APPLICATION_ENV as your hook for the env configs.
I hope it helps!
Upvotes: 1