Setting up Drupal 8 multisites

Submitted by Juan on Wed, 07/13/2016 - 15:50
Lego construction blocks

Drupal has the ability to mount multiple websites within one single Drupal instance. How is convenient to use this feature? It's a great idea to consider when we have several sites which shares similar features. For instance, if we have several websites where we must implement the same modules or share one same visual theme, it could be convenient to integrate them as part of a Drupal multisite. The advantage of doing that is the maintenance tasks become easier when updating the Drupal core and its modules.

For purposes of this test I will emulate the creation of two children from my main website: one for HATR Project and one for a blog called Dev Notes.

First we must create a database for each site we want to integrate in our multisite. In this example I will use different MySQL user accounts for the databases:

CREATE USER hatr@localhost IDENTIFIED BY 'password1234';
CREATE USER devnotes@localhost IDENTIFIED BY 'password5678';
GRANT ALL PRIVILEGES ON hatr.* TO hatr@localhost;
GRANT ALL PRIVILEGES ON devnotes.* TO devnotes@localhost;

We must add the children sites in the /sites/sites.php configuration file. This file must have the same format as example.sites.php located in the same folder. You can copy and use it as a template:

cp example.sites.php sites.php

We add the next lines into sites.php:

$sites = array(
// HATR Project
'' => 'hatr',
// Dev Notes
'' => 'devnotes',

The keys of the $sites array must have the following format: portnumber.domain.folder. Please watch here I don't care about the folder name at the ending of the string as I want to access to my website from the root URL. For instance, my website will be accessible from, not from something like

The values on the array corresponds to the folder name where the children sites configuration will be placed, so we must go later to the /sites folder of the parent Drupal site and create there two new folders: /sites/hatr and /sites/devnotes on this example:

mkdir hatr
mkdir devnotes

Now we must copy the default configuration files to the newly created folders. Run the following commands from the directory /sites/default:

cp default.settings.php ../hatr/settings.php
cp default.settings.php ../devnotes/settings.php
cp ../hatr/services.yaml
cp ../devnotes/services.yaml

We must create the files and translations folders for each of the children sites as follows:

mkdir devnotes/files
mkdir devnotes/files/translations

These folders must have writing permissions enabled to install Drupal. The next step is to point the subdomain on the Apache server configuration. Each children site must have a configuration file on /etc/apache2/sites-available/hatr.conf with the following parameters:

<VirtualHost *:85>
    DocumentRoot /var/www/jdeleon/

    ErrorLog ${APACHE_LOG_DIR}/hatr-error.log
    CustomLog ${APACHE_LOG_DIR}/hatr-access.log combined

Here is important to say that each site must point to its parent's location, not the newly created folder on /sites. We must replicate the same Apache configuration file for each children, in my case, devnotes. After that we have to activate the sites and restart the server so the changes take effect:

sudo a2ensite hatr
sudo a2ensite devnotes
sudo service apache2 restart

Don't forget to edit your local host file on your computer to let your new websites be accessible from the URL. In my case I had to point my two new subdomains to my virtual machine's IP as setting only the parent website domain is not enough. In my case I executed the next command on the terminal:

sudo nano /etc/hosts

And added the next two lines:

And voilà! When I go to on my browser looks like I'm ready to install my new website.