Last updated December 31, 2015. Created on July 3, 2014.
Edited by Christopher James Francis Rodgers, hellyj, woei, Johnnie Walker. Log in to edit this page.

Multi-site Overview

A good overview video on the benefits and drawbacks of various multi-site configurations is "Talking Drupal #021 - Multisite" (This link starts the video at 7-min 19-sec) [2013.10.30 - YouTube: 56-min ] Although that video does not address Drupal 8 specifically, it does touch on all the major considerations of a multi-site setup.

Some Multi-Site Considerations

     Skip this section, and jump down to 'Configuration' ⤵

A multi-site Drupal 8 setup will save you 'disk space', and in theory, 'time'. Given the relatively cheap cost of electronic storage these days, disk space is of lesser importance, though not free. The major consideration you should have about whether or not to use a multi-site Drupal 8 configuration, is your time.

But in the interest of being complete, lets also consider disk space in detail, and lets start with that.

Disk Space

All Drupal sites, including Drupal 8, require: a codebase, and a database. The codebase is a single set of directories and files. The database is quite separate from the codebase, and is not stored within the codebase.

Codebase

The codebase will at first contain only the 'Drupal Core'. Later, it will include any add-on Modules and Themes (more commonly referred to as 'Contrib' modules and themes, because they are 'contributed' free-of-charge by the Drupal community). The codebase will also later contain any other files you, and your users, add to the site, including images, audio files, video, etc.

Drupal Core: (D8.0.1 as example) 51-Megabytes.

  • 63-Modules: 25-Megabytes. 41 of these are enabled by default using the 'Standard' installation. (as opposed to the only other installation option, 'Minimal', which is recommended for advanced users only)

  • 3-Themes: 0.5-Megabytes. 2 of these are enabled by default.

Let's assume that the average sizes of the Core modules and themes represents a good average for Contrib modules and themes; and that you, for example, install an additional 20-modules, and 2-themes.

In that example, you would be saving 65-MB per domain for your Core, Modules, and Themes, by using a multi-site setup as opposed to having each domain as a separate Drupal 8 installation.

If, additionally, you will have files that can be shared across domains, and you know how to do that, then you will also save on disk space by only needing one set of those shared files, instead of one set of identical files per domain.

65-MB per domain is not in itself a lot, but if your sites warrant being automatically backed-up every 5-minutes, then the disk-storage space savings from using a multi-site Drupal 8 configuration will add up.

Database

The database is where all of the textual content of a site is stored.

It is recommended that you use a separate database for each site.

It is possible for you to have all sites share a single database, and distinguish each site's database tables from each other by, for example, using a different database-table-prefix for each site, but...

If there is any possibility that at some point in the future you might want to (or need to) remove a single site from the multi-site setup, you will most definitely want to have used a separate database for each site. It is infinitely easier to simply extract a single site's database from a multi-site setup, than it is to try and extract a single site's database-tables from a shared database (if that is even feasible).

And, for security reasons, and reasons having to do with developmental glitches, when you have separate databases per domain, it prevents all domains from being affected if one domain is adversely affected. This is particularly important if any of the domains will be administered by others, and especially if separate domains are for separate business clients.

Initially, a Drupal 8 database occupies about 61-Megabytes of disk-space on my computer's hard drive, though when I export it to be saved as a backup, its size is 8MB. And, by the way, a new D8 install has 66 database tables.

Being new to Drupal 8, I can only say that with Drupal 7, a fresh install has 74-tables (Local install using 'Acquia Dev Desktop 2'), and that my three online sites have between 114, and 136-tables each.

I would conclude, therefore, that you would save 61-MB per domain by sharing a single database across all domains; plus 8-MB per domain per backup. So, if you were to carry a running total of 100 backups online at a time, at $1 per month per Gigabyte of storage, the cost savings of using a shared database, instead of one database per domain, would come to $6 per month. But, if ever you have to spend a week of 16-hour days trying to extract a site's tables from a shared database, or undo some other complication caused by your choice to share domains in one database, and if you figure your time is worth $50 dollars an hour, it would take your client 75 years to break even. And if you had to do that on your own time, you would surely agree with the following.

I would recommend that you Not share databases across domains, particularly not when the domains are for separate business clients.

Final database note: It has been that suggested that using a single database might be a benefit in the case where a web-host limits your number of databases. From personal experience, I encourage you to shop carefully before you settle on a contract with any shared hosting service. Taking BlueHost as an example, I had been using their least expensive hosting plan, which was advertised as having 'unlimited storage, bandwidth, and databases'. But then after some years into our happy relationship, my sites were shut down because I had surpassed a 1000-database-table limit. I was able to quickly remedy that sad situation, however, by deleting several of my test-case sites (not knowing how to operate Locally), so that my number of Drupal 7 sites numbered not more than seven.

Time.

The real benefit of Drupal 8 multi-site configurations is in its potential to save you time and effort in development, and maintenance.

Updating all of your sites each time Drupal Core has an update, as for example from version 8.0.0 to 8.0.1, is done more easily with a multi-site setup, because you only have to update a single set of Drupal Core files in one codebase.

News flash: I just watched the video recommend at this page top, and I learned something new; just now. Whereas manually updating Drupal, including the backup first, takes me an average of an hour per site, if I were using Drush the update process would take less than 2-minutes. So, actually, learning Drush might be a better use of my limited time on this Earth, rather than pursuing this right now. Sorry to bail on you.

Yes, a multi-site setup would save you time, however, you have to learn how to actually do it. Unfortunately, I cannot tell you how long it will take you to learn even the basics, and not because I have any doubt about any average person's ability to follow a simple set of steps to do it. It is just that I have never seen a step-by-step, mouse-click by mouse-click, keystoke-by-keystroke guide, or anything even close, which attempts to thoroughly explain in detail to beginners how to do it, and which anticipates the expected stumbling blocks along the way. You see, I myself do not know how to do it. But if my seven years of experience at drupal.org have taught me anything, it has taught me that I could expect to figure it out if I kept at it, so long as I kept my search setting at Google at 100 results a page for a page or two or three. I wouldn't take me forever; let's say, um, ..what year is it now .... I wish you all the best, and hope if you figure it out that you will take time to precisely detail the steps on this page for setting up a multi-site Drupal 8. You gotta figure that for every hour you could have saved if someone had detailed it for you first, by your detailing on this page what you learned, you will easily be saving a thousand individuals that hour, at least, over the next ten years of D8's lifetime. And that way the first five comments on this page will not continue to grow in-kind. Thanking you in advance for your help for the poor newbie to come.

Configuration

Configuration of multi-site on Drupal 8 is similar to previous Drupal versions. However, unlike previous versions, Drupal 8 requires multi-site to be explicitly enabled before additional sites are recognized.

Enabling multi-site with sites.php

Multi-site requires the existence of the sites.php file in the sites directory. This file does not exist by default. If this file does not yet exist, copy sites/example.sites.php as follows:

$ cp sites/example.sites.php sites/sites.php
You should edit the sites.php file for your cases, for example:

$sites = array(
'site1.yourdomain.com' => 'site1',
'site2.anotherdomain.net' => 'site2'
);

Site directories

Each site in a multi-site installation is signified by a directory under the sites directory. Drupal is installed with a sites/default directory. Additional sites are represented by creating additional directories. For example:

  • sites/site1
  • sites/site2

Each new site directory must have a settings.php file in order for Drupal to recognize it. On initial installation of a site, copy sites/default/default.settings.php as follows:

$ cp -a sites/default/default.settings.php sites/[new site directory]/settings.php
$ cp -a sites/default/default.services.yml sites/[new site directory]/services.yml
You need -a to preserve the permissions.
Then, you should visit the url domain and start to install a new Drupal site, for example:
http://site1.yourdomain.com/
http://site2.anotherdomain.net/
Also, you should make sure your web server (nginx, apache or IIS) already finished the setting and your DNS records should be mapped ready.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

rhuffstedtler’s picture

I see variants of multisite/multi-site with and without the hyphen in various docs. Has the doc team set a standard for which is the proper spelling?

othermachines’s picture

However, unlike previous versions, Drupal 8 requires multisite to be explicitly enabled before additional sites are recognized.

sites.php only needs to be enabled - is that correct? As long as the site folders in sites/ follow accepted discoverability rules, nothing has to actually be set here, does it? I think this should be clarified.

tnanek’s picture

Presume this has changed, as beta-15 is lacking the file example.sites.php. I'm just not sure if that file would still be used if it were there myself, or if that was integrated elsewhere.

soundbyte’s picture

I seem to remember having to install the primary/default site first in D7. With the additional site directories set up with their own settings.php etc, do we still have to bother with the default site install with D8?

hellyj’s picture

aloha.

1) I’m teaching a class using Drupal8 in Maui this semester and am having trouble setting up multi-site configuration following these instructions. Been using D6 a long-time but now making jump to D8.
2) I'm running a new install on Debian and have the default site working but cannot find the magic to run the student sites. The idea is to run student sites (e.g., student1.localhost) on the same server.
3) I've renamed the local server to be ics385.net in /etc/hosts to avoid have to use the LAN address (i.e., 192.168.0.9) but that should work in principle, no?
4) When I invoke the default site, http://ics385.net, it's fine. However when I invoke http://student1.ics385.net, I get a timeout error.

Any suggestions?
Mahalo
J.

MakeOnlineShop’s picture

Hello,

Same problem here, how to set up a multi installation for D8 ?

sites.php is in mydomain.com/sites

then I add mydomain.com folder in "sites" folder

and put settings.php in this folder

I did this after having installed a standard unique site first, then tried to modify, could it be the source of the problem ?

Thanks.

MakeOnlineShop’s picture

Hello again,

It seems that I forgot to copy these 2 files in mydomain.com/sites/mydomain.com

default.services.yml
default.settings.php

Then the settings.php that I previously added manually in this folder (and deleted after) has been created automatically.

But i still don't know why in the explanation above it is written to visit
http://site1.yourdomain.com/
http://site2.anotherdomain.net/

I just went to yourdomain.com and the installation started, not site1.yourdomain.com

Maybe it is because I have only 1 site installed now ? But the multi install seems ready for the next one !

RaisinBranCrunch’s picture

I've gotten this working by following these instructions. Things to be careful/aware of:
- Make sure you've added a ServerAlias in Apache if that's what you're using, e.g. site1.example.com and make sure to reload the configuration
- If you're using a hosts file to reach this server, make sure you've got entries for both www.example.com and site1.example.com
- Make sure the permissions are correct for everything under sites/site1/files. After installing via drush I had to correct these.
- If you cd into sites/site1, all drush commands will run for that site, which is convenient.

davidh59’s picture

It is astounding to me that as advanced as Drupal is, and with the advent of Drupal 8, there are things that are still perplexing and which appear to defy explanation.

I have one site set up under the default folder.

httpdocs/sites/default

Works fine, file system is logical (site.com/files).

I have another site set up like this:

httpdocs/sites/site1.com

When I go here:

http://site1.com/admin/config/media/file-system

I am shown this:

Public file system path
sites/site1.com/files

Public file base URL
http://site1.com/sites/site1.com/files

This public file base URL setup cannot possibly be correct.

Should it not be:
http://site1.com/files

The following alterations to settings.php lead to black text on white background. All styling is gone, etc.

If anyone has a clue as to how to adjust these settings I'd be grateful if you'd please share. Thank you.

/**
* Public file base URL:
*
* An alternative base URL to be used for serving public files. This must
* include any leading directory path.
*
* A different value from the domain used by Drupal to be used for accessing
* public files. This can be used for a simple CDN integration, or to improve
* security by serving user-uploaded files from a different domain or subdomain
* pointing to the same server. Do not include a trailing slash.
*/
# $settings['file_public_base_url'] = 'http://site.com/files';

/**
* Public file path:
*
* A local file system path where public files will be stored. This directory
* must exist and be writable by Drupal. This directory must be relative to
* the Drupal installation directory and be accessible over the web.
*/
#  $settings['file_public_path'] = 'sites/site1.com/files';
vaccinemedia’s picture

The files are accessed on the server from the root of the website. In this case both sites in a multisite installation have the same document root. It is from this document root where the files are accessed. so in terms of there the files are on site1.com they are in:
DOCROOT/sites/sitename/files where sideman = site1.com in this case.

Also in the case above, the base URL is the url of the site - in this case http://site1.com not:
# $settings['file_public_base_url'] = 'http://site.com/files';

I'm a Drupal Website Developer who also produces Gigapixel Virtual tours.

umeshpatil’s picture

Hello Guys,

I dont know if it is right to ask this question, but I was wondering what would be the best practice?
What would be appropriate if my website is multilingual, whether to go with multisite-multilingual configuration or multidomain-multilingual configuration?

Thanks in Advance!!

vaccinemedia’s picture

When you say multi domain do you refer to using something like the domain access module to allow publishing under multiple domains on a single Drupal installation instead of the multisite method?

I'm a Drupal Website Developer who also produces Gigapixel Virtual tours.

rovo’s picture

Is there a way to utilize Drupal's multi-site in a way thats similar to many conventional multi-tenant apps(such as Zendesk, Basecamp)? For example, an enduser can register a new account and enter a custom subdomain, then a new Drupal environment is automatically spun up for them?

Currently, it seems like the only way to achieve this with Drupal's multi-site is to manually provision the files and database.

Greatly appreciate any insights.

*I have tried Aegir, but spins up entirely separate codebases, more along the lines of single-tenancy.