After create many testdrive application with Yii, I found out a better way to set up a dev environment using Apache Virtual host feature, and Yii flexible configuration files.
In the index file, I use this setting:
if (! empty($_SERVER['HTTP_HOST'])){
$hostname = $_SERVER['HTTP_HOST'];
} elseif (! empty($_SERVER['SERVER_ADDR'])) {
$hostname = $_SERVER['SERVER_ADDR'];
} else {
$hostname = 'main';
}
// change the following paths if necessary
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/'.$hostname.'.php';
Declare separate configuration files, equivalent to $hostname, to support multiple project based on the same code base.
protected/config/dev.localhost.php --> This file will be used when access URL dev.localhost/yiiproject
protected/config/test.localhost.php --> This file will be used when access URL test.localhost/yiiproject
By adding virtual host and edit the /etc/hosts file, I can easily point those hostname into localhost.
This save alot of copy and paste between projects, because they all use the same code base.