Drupal Multisite
The following guide outlines the steps needed to configure a Drupal 8 multisite setup. This guide is a work in progress and includes only sample configurations. Other options—such as HTTPS, different web servers and databases, or advanced virtual host configurations—are available.
It is worth noting that using the Aegir hosting system is the preferred method. Aegir automates the complex setup process using secure best practices, including automatic virtual host configuration for Apache and Nginx, HTTPS support, Composer command execution, and more. See the Platform Setup Documentation—Aegir-speak for a multisite codebase.
Process Overview:
1. Install a Drupal 8 instance that will act as the root site of our multisite installation. In this example, the root site will be named d8multisite
, accessible at d8multisite.com
and installed at /var/www/d8multisite
.
2. Create a multisite named site1
, accessible at site1.d8multisite.com
.
3. Configure site1
to have its own modules independent of the root site.
Step 1: Create the Master Site
Start by installing a copy of Drupal 8 on your server. Refer to the Drupal 8 Installation Documentation if you're unfamiliar with the process.
1.1: Create a database for the root site, e.g., d8multisite
.
1.2: Download and extract Drupal 8 into your web root.
1.3: Create a virtual host definition for the root site. See virtual host configuration. Apache example:
ServerAdmin me@domain.com DocumentRoot /var/www/d8multisite ServerName d8multisite.com ServerAlias www.d8multisite.com Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted ErrorLog ${APACHE_LOG_DIR}/d8multisite_error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/d8multisite_access.log combined
1.4: Complete the Drupal installation at d8multisite.com
.
Step 2: Configure First Multisite Instance
2.1: Create a folder for site1
: /d8multisite/sites/site1.d8multisite.com
2.2: Create a new database for site1
, e.g., d8multisite_site1
2.3: Copy example.sites.php
to sites.php
cp sites/example.sites.php sites/sites.php
2.4: Edit sites.php
and append:
$sites['site1.d8multisite.com'] = 'site1.d8multisite.com';
2.5: Create a virtual host for site1
:
ServerAdmin me@domain.com DocumentRoot /var/www/d8multisite ServerName site1.d8multisite.com Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted ErrorLog ${APACHE_LOG_DIR}/site1-d8multisite_error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/site1-d8multisite_access.log combined
2.6: Copy the default settings file into the new site folder:
cp sites/default/default.settings.php sites/site1.d8multisite.com/settings.php
2.7: Visit site1.d8multisite.com
to complete the Drupal installation.
Step 3: Enable Site-Specific Modules
To allow site1
to have its own modules:
- Create a
modules
folder insite1
:/d8multisite/sites/site1.d8multisite.com/modules
- Give Apache write permissions:
chown www-data /d8multisite/sites/site1.d8multisite.com/modules
- Verify:
- Install Pathauto in the root site via Drush:
drush dl pathauto
- Switch to the
site1
directory and install Display Suite:drush dl ds
- Confirm that:
- Pathauto is available on both sites
- Display Suite is only available on
site1
- Install Pathauto in the root site via Drush:
Note: This applies similarly to themes, libraries, and files. Further testing and documentation is needed.
Using Drush with Multisites
You can use the -l
option:
drush -l example.com command
Or use a site alias:
drush @alias command
To view site aliases:
drush site:alias
Example output:
@sub1.dev:
root: /var/www/mydomain.com/web
uri: "https://sub1.mydomain.com"
@default.dev:
root: /var/www/mydomain.com/web
uri: "https://sub2.mydomain.com"
@third.dev:
root: /var/www/mydomain.com/web
uri: "https://thirddomain.com"
To run a Drush command for a specific site:
drush @sub1 updb
Note: Avoid using ".dev" in the alias name itself.
Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.