Running Several Different Instances Of Yii Application?

I want to run several different instances of a Yii application with different options (in fact every instance differs from other by the value of MySQL login and password, so effectively using different databases).

If we have only two instances it can be done by creating two.php with a copy of index.php and specify the info for alternate config there.

But what if I want to run more than two (an unlimited number) of instances of my application? How could this be done?

This could be done adding ?xxx=yyy to the URL, but when clicking a link or submitting a form, Yii would "forget" that ?xxx=yyy specifying that it is for an alternate app instance.

create a multiomain.php in protected/config with this code:

$myid = $_GET['xxx'];

return CMap::mergeArray(





			'connectionString' => 'mysql:host=localhost;dbname=mydatabase_'. $myid ,

			'emulatePrepare' => true,

			'username' => 'userdatabase_'. $myid,

			'password' => 'password_'. $myid ,

			'charset' => 'utf8',




but be careful with $myid!, it should be purified from malicius characters

The trouble is to preserve $myid when one clicks links or submit forms with ?xxx=

It seems that your code does not do that.

you could set it in session

Yii::app()->user->setState('myid', $myid);


Yii::app()->session['myid']= $myid;