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

  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
  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[''] = 'drupal_multi1';
    2. $sites[''] = 'drupal_multi2';
  10. Now proceed with default installation of your files by visiting these urls in host browser and .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.