Environment are tightly related to development & deployment workflow (product cycle).
For example - small projects are suitable to deploy directly from localhost to online.
Bigger projects need more staged workflow of deployment, e.g. localhost -> testing -> production.
On most projects, we use following environments:
phase 1: -> local development (devel environment)
phase 2: -> test server 1 (local) (testing environment)
phase 3: -> test server 2 (production server copy) (testing environment)
phase 4: -> production server (production environment)
Since Yii 1.x does not assume multiple environments, we solved the issue via loading config.php files in a cascading style - meaning following configuration file can overwrite any previously loaded configuration setting. This actually the same logic like in other frameworks, e.g. ZF1.
Here is example:
(1) in /config/main.php:
...
// some production config code (always loaded first)
...
if(!Config::isProduction() && is_file(dirname(__FILE__).'/main-test.php')){
require(dirname(__FILE__).'/main-test.php');
}
(2) in /config/main-test.php:
...
// some testing config code (overrides some configuration from main.php)
...
if(Config::isDevelopment() && is_file(dirname(__FILE__).'/main-development.php')){
require(dirname(__FILE__).'/main-development.php');
}
(3) in /config/main-development.php:
...
// some development config code shared amongst all developers
// (overrides configuration from main.php and main-test.php)
...
if(is_file(dirname(__FILE__).'/main-developer.php')){
require(dirname(__FILE__).'/main-developer.php');
}
(4) in /config/main-developer.php:
...
// setting specific to particular developer, this file is never committed
// (overrides configuration from main.php, main-test.php and main-development.php)
...
The Config object is simply check for specific IPs e.g.:
class Config{
public static function isProduction(){
// return TRUE if current server is running on domain "*.mydomain.com"
return false !== stripos($_SERVER['SERVER_NAME'], 'mydomain.com');
}
public static function isDevelopment(){
// return TRUE if current server is in intranet with IP 10.20.30.*
return false !== strpos($_SERVER['SERVER_NAME'], '10.20.30.');
}
}
Perhaps this gives some ideas on solving the issue with multiple environments.
Unfortunatelly, it is impossible to unify deployment workflows - so in the end it is questionable whether framework can solve such a specific need…
Cheers.
Lubos