one Yii for Several sites, is it possible ?


I installed yii on the web root directory : C:\inetpub\wwwroot\yii

and I would use yii on my webSite which is on another directory : C:\inetpub\wwwroot\myWebSite

Does it possible ? how ?

If not, I must install Yii on my website directory, mustn’t?


customize these lines in the start script

require(__DIR__ . '/../vendor/autoload.php');

require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

Depending on config script relative placement

$config = require(__DIR__ . '/../config/web.php');

I think it should be enough even in Yii2.

At least if all sites share the same dependencies.

Thanks Tri,

start script means for you ? index.php of Yii ?

C:\inetpub\wwwroot\yii\web\index.php ? Must I change it or another?

If you speak about this file like as start file, I cannot use same Api for several different website, can I ?

Every web application has , I assume, its own configuration and start/entry script

Different sites, the way I think about it would have separate API’s or they would be the same site, or am I wrong?

How to maintain framework as well as application(s) is another thing to think about before implementing something like this.


Now I undersand I have two different sites so I need two Yii API…


Note what I added to my first message

In Yii 1.x it should work.

I just tried this in Yii2 with two instances of the basic application template in parallel subdirs. I copied the vendor dir to a common dir and pointed the index.php’s there as described.

[s]The application needs access to the vendor dir (expected).

So in the applications vendor dir’s I just commented out the subdir yiisoft and the file autoload.php.


Actually I got it working pointing vendorPath to the common vendor dir. This worked:

$config = [

    'vendorPath' => __DIR__ . '/../../<my common dir>/vendor',

    'id' => 'basic',

    'basePath' => dirname(__DIR__),

Seems to work but not worth the effort for just two instances. Then perhaps more work separating content from the application and common vendor dir and don’t forget the maintenance mess.

So, I got it working pointing vendorPath to the common Yii dir.

But still possible maintenance mess.

Better placement (all changes in start script)

require(__DIR__ . '/../../<my common dir>/vendor/autoload.php');

require(__DIR__ . '/../../<my common dir>/vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/web.php');

$config['vendorPath'] = __DIR__ . '/../../<my common dir>/vendor';

(new yii\web\Application($config))->run();