My client wants me to develop a website, which can give a subdomain for each user.
I want to achieve this using Yii since there are features inside that can be achieved easily by my previous Yii codes, but I am not sure where to start from.
Even better if each user has his own SQL database.
So far in my opinion the idea is to duplicate the ‘protected’ folder for the files and run certain SQL statement to duplicate the table using php exec or something.
I have done something very similar with some projects at work.
You make your domain with all subdomains point to the server in DNS. The webserver is configured to receive all requests for that domain, and the same application instance is run for every request (*.domain.com -> /var/www/youapplication/). Then you use apache rewrites to detect if request has "www" or something else as subdomain. If not "www", then rewrite the request to "www.domain.com/r=blog/view&username=%1"
The is not a detailed recipie, but gives you the idea of what to do.
My last project uses one instance of an application for multiple customers. Each customer is separated with its own configuration file, and the index.php file will detect which subdomain is requested, and load the appropriate configuration file.
If you want a different db for each subdomain (=user) you can do this like below.
But you have to create the db by a script on user registration.
Define a const (for example SUBDOMAIN_DBNAME) with the value of the subdomain in your index.php
...
//extract the subdomain and add a prefix 'subdomain_' to the dbname
$dbname='subdomain_'.array_shift(explode(".",$_SERVER['HTTP_HOST']));
define('SUBDOMAIN_DBNAME',$dbname);
...
Yii::createWebApplication($config)->run();