You are here

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

    1. <VirtualHost *:80>
    2. ServerAdmin webmaster@drupal_multi.mycentos.com
    3. DocumentRoot /var/www/html/drupal_multi
    4. ServerName drupal_multi.mycentos.com
    5. ErrorLog logs/drupal_multi.mycentos.com-error_log
    6. CustomLog logs/drupal_multi.mycentos.com-access_log common
    7.  
    8. <Directory /var/www/html/drupal_multi>
    9. AllowOverride All
    10. Order allow,deny
    11. Allow from all
    12. </Directory>
    13.  
    14. </VirtualHost>
    15.  
    16. <VirtualHost *:80>
    17. ServerAdmin webmaster@drupal_multi1.mycentos.com
    18. DocumentRoot /var/www/html/drupal_multi/
    19. ServerName drupal_multi1.mycentos.com
    20. ErrorLog logs/drupal_multi1.mycentos.com-error_log
    21. CustomLog logs/drupal_multi1.mycentos.com-access_log common
    22.  
    23. <Directory /var/www/html/drupal_multi1>
    24. AllowOverride All
    25. Order allow,deny
    26. Allow from all
    27. </Directory>
    28.  
    29. </VirtualHost>
    30.  
    31. <VirtualHost *:80>
    32. ServerAdmin webmaster@drupal_multi2.mycentos.com
    33. DocumentRoot /var/www/html/drupal_multi/
    34. ServerName drupal_multi2.mycentos.com
    35. ErrorLog logs/drupal_multi2.mycentos.com-error_log
    36. CustomLog logs/drupal_multi2.mycentos.com-access_log common
    37.  
    38. <Directory /var/www/html/drupal_multi2>
    39. AllowOverride All
    40. Order allow,deny
    41. Allow from all
    42. </Directory>
    43.  
    44. </VirtualHost>
  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.

    1. 127.0.0.1 drupal_multi.mycentos.com
    2. 127.0.0.1 drupal_multi1.mycentos.com
    3. 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
    1. $sites['4567.drupal_multi1.mycentos.com'] = 'drupal_multi1';
    2. $sites['4567.drupal_multi2.mycentos.com'] = 'drupal_multi2';
  10. 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.