There is an incredibly easy way to create multiple Drupal sites. You don’t need to duplicate the code. You can have multiple sites, with different content, users, and themes since each site can use a different database. They will all run on a single codebase and will be able to share modules. This is one of Drupal’s greatest features called Multi-site. It was first implemented in Drupal 4, and it is here now in Drupal 8.
To get started, go ahead and download Drupal.
Then, upload and extract all the files into a new folder for Drupal. For example:
I will be creating two sites, one for dogs, and the other for cats.
These multiple sites can be accessed either from subdomains or subdirectories. If you are going to use subdomains, go ahead and create them. However, if you are going to use subdirectories, hold off until later, since you will have to remove it anyways.
I want the dogs website to be accessed by a subdomain and the cats website by a subdirectory, so I will create
Now create a separate database for each site. Also, create a user or two to access these databases.
I will name my databases
user_cats which will be accessed by user
user_drupal who will have privileges:
ALTER, CREATE, CREATE TEMPORARY TABLES, DELETE, DROP, INDEX, INSERT, SELECT, AND UPDATE.
The Technical Part
Navigate into the directory:
We need to tell Drupal we are going to have multiple sites. To do this, create a file called
sites.php. You can find extra examples and documentation of how to set it up in the
This file will contain an
$sites array containing all the rules. For each index, the key will be the formatted address the website will be accessed at, and the value will be what folder to look in.
Format of each index:
'<port>.<domain>.<path>' => 'directory'.
$sites = array(
'dogs.kalose.net' => 'dogs',
'www.kalose.net.cats' => 'cats',
$sites = array(
'8080.www.drupal.org.mysite.test' => 'example.com',
Since we said
dogs.kalose.net was going to use the
/dogs/ folder and
www.kalose.net/cats/ was going to use the
/cats/ folder, these folders need to be created:
SSH / Shell / Terminal
Connect to your webserver via SSH. If you’re on Windows, you can use PuTTY.
/drupal/sites/default/ site will have default files we need to copy into each of our sites. Copy these files using the
cp command in the sites directory:
cp default/default.settings.php dogs/settings.php
cp default/default.settings.php cats/settings.php
cp default/default.services.yml dogs/services.yml
cp default/default.services.yml cats/services.yml
Now we have successfully set up Drupal for multi-site. Although, if you visit
www.kalose.net/cats/ it will be blank. Why? How does the web server know to point these sites to the
/drupal/ directory? This is why we need to make symbolic links from
If a subdirectory is created when you create a subdomain, delete that directory.
Now time to create the symbolic links. This is why we did’t have to create the
/cats/ subdirectory. The symbolic link will automatically point
/drupal/ like they are the same folder.
ln -s drupal dogs
ln -s drupal cats
* You may notice that these folders/links have all permissions (
chmod 777). You don’t need to worry about this because these permissions won’t be used, instead the permissions of
/drupal/ or the file/folder you are linking to will be used.
All that is left to do now is to install Drupal. I can visit
www.kalose.net/cats/ and set them up using databases
user_cats. Using Multi-site, these sites can be completely different except for the fact that they share the same underlying code.