How to use Drupal 7 multisite feature

At Sparxsys we have a client who run one internal website in their company. Now recently a requirement came from one of the department that they also want to run a similar website with exact same features but with little modifications here and there. Earlier we thought that we will deploy a totally new Drupal installation but then we realized that this is a perfect use case for Drupal multisite feature.

Drupal is a powerful cms and it comes with a unique feature known as multisite. Multisite means using one Drupal installation you can run multiple sites on it i.e. each of those site will share a common code base but different database. Let me show you how to setup 2 sites on a single Drupal installation. The advantage of this approach is that the new sites will use the same Drupal code base and it becomes very easy for the developer to manage the modules and code. Of course this approach is recommended only when these two sites are for similar purpose and for the same client.

Tools used

  • Virtualbox
  • Vagrant
  • Guest OS: centos-6.5
  • Host OS: windows xp
  • Server: Apache 2.2
  • Database: Mysql

Now first of all make sure to setup your environment. We are going to setup 2 more websites using the same code base and eventually we will have 3 sites. Here are the steps to follow.

  1. Create 3 databases name them as drupal_multi, drupal_multi1, drupal_multi2. First database is for default Drupal installation and other 2 are for our other sites.
  2. Now edit you Apache configuration file to create 3 virtual hosts.
  3. Add the following lines


    ServerAdmin webmaster@drupal_multi.mycentos.com
    DocumentRoot /var/www/html/drupal_multi
    ServerName drupal_multi.mycentos.com
    ErrorLog logs/drupal_multi.mycentos.com-error_log
    CustomLog logs/drupal_multi.mycentos.com-access_log common


    AllowOverride All
    Order allow,deny
    Allow from all


    ServerAdmin webmaster@drupal_multi1.mycentos.com
    DocumentRoot /var/www/html/drupal_multi/
    ServerName drupal_multi1.mycentos.com
    ErrorLog logs/drupal_multi1.mycentos.com-error_log
    CustomLog logs/drupal_multi1.mycentos.com-access_log common


    AllowOverride All
    Order allow,deny
    Allow from all


    ServerAdmin webmaster@drupal_multi2.mycentos.com
    DocumentRoot /var/www/html/drupal_multi/
    ServerName drupal_multi2.mycentos.com
    ErrorLog logs/drupal_multi2.mycentos.com-error_log
    CustomLog logs/drupal_multi2.mycentos.com-access_log common


    AllowOverride All
    Order allow,deny
    Allow from all


  4. Also add the hosts in windows host file. In windows xp host file is located at c:/windows/system32/deives/etc/host.
  5. Add these lines.


    127.0.0.1 drupal_multi.mycentos.com
    127.0.0.1 drupal_multi1.mycentos.com
    127.0.0.1 drupal_multi2.mycentos.com

  6. Now go into your guest OS and move into diectory /var/www/html and create a folder named dupal_multi and do the default installation of Drupal by visiting this in your host OS browser http://drupal_multi.mycentos.com:4567/install.php
  7. After doing default installation go /var/www/html/drupal_multi/sites and create 2 folders namely drupal_multi1 and drupal_multi2
  8. Copy default.settings.php file from default folder as settings.php into drupal_multi1 and drupal_multi2 folders
  9. Copy sites/example.sites.php to sites/sites.php and added the following lines in the end

  10. $sites['4567.drupal_multi1.mycentos.com'] = 'drupal_multi1';
    $sites['4567.drupal_multi2.mycentos.com'] = 'drupal_multi2';

  11. Now proceed with default installation of your files by visiting these urls in host browser http://drupal_multi1.mycentos.com:4567/install.php and http://drupal_multi2.mycentos.com:4567/install.php .Just remember to select drupal_multi1 database for drupal_multi1 site and drupal_multi2 database for drupal_multi2 site

After following these steps you will be having 2 sites installed on a single Drupal installation .You can modify the above steps to install as many sites as you want.