Search code examples
build-processmultiple-databasesapplication-designmultiple-domains

Multiple websites running on same codebase?


We are developing an application that would be offered as a hosted solution. I am struck with understanding how can i use multiple sites with same code without duplicating base code.

eg: website 1: www.example.com and website 2: www.sample.com will run on same code, but would have different configuration settings, and different theme... like we run our own domain names in wordpress.

i wish to know how can i do this.

also in case of database.. would it be better i create individual databases for each website or use the same database with website ID as a column in each table.

pls help me.

[clarification] its not domain alias. like... it would be a service. where different clients will be offered the same application on their own domain name with different theme. something like what blogger does.. with own domain names but same blog application

[technology] specifically am looking at how to use the host name to determine which configuration to use we are using PHP and MySQL


Solution

  • Reusing code is definitely desirable. It is hard to imagine from your posts how different the sites will be from each other. Are we talking about logos, and color schemes or different functionality?

    I'll start with the different look & feel. I'll also assume that this is the only application on the server.

    I recommend planning your directory structure carefully. Something like:

    www-root/  
       / lib  
       / themes
            / domain1  
            / domain2  
    
    
    index.php:
    
    <?php
    $host = $_SERVER['HTTP_HOST'];
    $include_theme = "themes/" . $host . "/configuration.php";
    //make sure the file exists
    require_once($include_theme);
    

    This is a simplistic approach but something to thing about.