0

I want to use single yii2 web application with multiple databases and URLs.

Actually, I have a single web application on a single web server and I want to give subscription of it to different user/companies. Each company will have it's own separate database. e.g.

company1 will want url xyz.com with database db1.
company2 will want url ab.xyz.com with database db2.
company3 will want url cd.xyz.com with database db3.
company4 will want url ef.xyz.com with database db4.

How can I implement the above scenario in yii2 web application? Also the url should be in respect to the companies.(e.g. if company3 logins then url should be cd.xyz.com/login if company4 wants to login then url should be ef.xyz.com/login and so on.)

1
  • where have you placed these configurations company, url and database ? You can create multiple configuration file one per company. Based on sever URL include that file.. config/db/xyz.config.php config/db/ab.config.php .... You can include this in web/index.php $config = yii\helpers\ArrayHelper::merge( require(DIR . '/../../common/config/main.php'), require(DIR . '/../../common/config/main-local.php'), require(DIR . '/../config/main.php'), require(DIR . '/../config/main-local.php'), require(DIR . '/../config/db/xyz.config.php') ); Commented Jan 23, 2018 at 9:02

1 Answer 1

1

You can create multiple database connections within 1 app, read this and/or this.

In my opinion, managing which user connects to which database would be a mess. I would deploy 4 separate apps (or as many as you need), each with its own database. To mantain the code base, I would create some system or a script that updates the 'updatable' files in all apps at once: models, controllers, etc. but not config files, static resources, ...

Sign up to request clarification or add additional context in comments.

1 Comment

Agreed. It is much simpler to maintain multiple instances of same app for different users rather than one big app with multiple connections. URL manager would be nightmare...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.