Drupal Multisite


Nowadays, businesses may have different branches or sub businesses. Some businesses may have branches in other countries. Those businesses may have the same company name but different products for each country. It's very common for businesses to be like that nowadays. 
Usually, businesses with this kind of setup, build multiple websites. Multiple websites should be a good solution however it could be very stressful to manage multiple websites at the same time. Additionally building multiple websites can result in a slower building process, scarce visibility, and lack of control. It could also take more time and cost more to create separate websites.

What is the solution then?

The solution is to use a multisite structure that allows you to create multiple websites with a common codebase. Using a multiple website setup would result in less time and work to build, and would still satisfy the requirement for each site needed to be set up. The multisite structure usually consists of one codebase and has different databases. Each database corresponds to a different site. And Drupal being one of the popular CMS today, we will discuss how we can create a multisite on the Drupal CMS.

Drupal CMS has a lot to offer. One feature of Drupal is the multisite setup.  Here are the steps you would need to do to create your very own Drupal 9 multisite!

1. Create the master site
   To begin the process, install a newly fresh Drupal 9 on your server. We will first create and determine the main site of your multisite setup.

   1.1 Create a database for your default/root site
   1.2 Update your Apache virtual hosts for your default/root site. If you need more details regarding on how to setup Apache on your server, you may visit this link. Here is also an example of how your Apache virtual host should look like
<VirtualHost *:80>
  # virtual host configuration for Drupal 9 multisite root site
  ServerAdmin me@domain.com
  DocumentRoot /var/www/drupal_multisite
  ServerName drupal_multisite.com
  ServerAlias www.drupal_multisite.com
  
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  
  <Directory /var/www/drupal_multisite>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

</VirtualHost>

   1.3 Continue to install Drupal by visiting drupal_multisite.com (the domain which you have added on your Apache virtual hosts). A UI will display for you to follow to complete the installation of your main site.

2. Configure your sites.php for Drupal to determine the multisite
    Since we now have the root/default site setup, we will create our sub-site.


    2.1 Create a directory for your sub-site.
    Ex. /drupal_multisite/sites/subsite1
    2.2 Create a database for your subsite1
    2.3 Copy the files inside drupal_multisite/sites/default/ to drupal_multisite/sites/subsite1/
    2.4 Edit the settings.php to point to the database you created for subsite1.
    2.5 Edit sites.php for Drupal to determine if the its the root/default site or subsite the user is trying to access
    Ex. $sites['subsite1.com'] = 'subsite1';
    2.6 Similar to step 1.2, update your vhosts.conf for your subsite to be accessed
    Ex. 


<VirtualHost *:80>
  ServerAdmin me@domain.com
  DocumentRoot /var/www/drupal_multisite
  ServerName www.subsite1.com
  
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  
  <Directory /var/www/drupal_multisite>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

 

3. Separate modules and theme
    At this point,  you have a Drupal multisite. You can access URL www.drupal_multisite.com for your root/default site and URL www.subsite1.com for your subsite. In this step, we will teach you how we can separate the modules and themes which should belong to only a specific site.
    3.1 Create a modules and themes directory under drupal_multisite/site/subsite1/ and drupal_multisite/site/default/
    3.2 If you have a module only for the default site move it to drupal_multisite/site/default/modules/

There it is! That is how you can create a multisite using the Drupal CMS.

Profile picture for user Gabriel Fernandez
Gabriel Fernandez Website Developer

Born and raised in an island in the Philippines! Never been outside the country (hopefully someday I will) Started working at Acret with zero Drupal knowledge, since then with the help from my fellow colleagues I have learned a lot about Drupal development and also a lot more about software development! I am still learning as of today so if you have anything to teach, please teach me sensei!