Multisite in Drupal 8

Preface

  1. Setting up default main/root Drupal site- “domain.com”
  2. Setting a sub-site “staging.domain.com”
    • Prerequisites
      • Creating a staging folder
      • Creating settings.php
      • Creating a sites.php file
  3. Adding a virtual host entry for both main and staging site
    • Adding virtual host entries
    • Enable the site
    • Add entry in /etc/hosts file
  4. Restart Apache
  5. Setting up “staging.domain.com” site
  1. Setting up default main/root Drupal site- “domain.com”

Setup a root site which should be a normal Drupal installation (while setting a fresh root site you can also follow virtual host steps mentioned in this article)

2. Setting a sub-site “staging.domain.com”

After the root site is set up, you can begin configuring first site called staging.

Here are the steps in this process:

i. Creating a staging folder
Create a folder for staging in your multisite: /domain/sites/staging.domain.com

Create a database for staging, ex: domainstaging

ii. Creating settings.php
Copy domain/sites/default/default.settings.php to the new site’s directory as settings.php:

iii. Creating sites.php
Make a copy of /domain/sites/example.sites.php called /domain/sites/sites.php

Edit sites.php so the end of the file looks like this:

# make the root drupal site aware of staging site:

$sites[‘staging.domain.com’] = ‘staging.domain.com’;

3. Adding virtual host entry for both main and staging site

Adding virtual host entries

This can be followed for all the sub-sites like staging in our case.
Create a new domain.conf file in /etc/apache2/sites-available directory
vi domain.com.conf
vi domain.lfc.com.conf

Following is the minimum virtual host entry in the above conf file-

<virtualhost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin webmaster@domain.com
ServerName  domain.com
ServerAlias domain.com

# Index file and Document Root (where the public files are located)

DirectoryIndex index.html
DocumentRoot /var/www/html/domain
<Directory “/var/www/html/domain”>
allow from all
order allow,deny
</Directory>

# Custom log file locations

#LogLevel warn
ErrorLog  /var/www/vhosts/domain.com/log/error.log
CustomLog /var/www/vhosts/domain.com/log/access.log combined
</virtualhost>

Enable the site

/etc/apache2/sites-available$ a2ensite domain.com
/etc/apache2/sites-available$ a2ensite staging.domain.com

Add new host entry in hosts file found at /etc/hosts

127.1.1.1 domain.com
127.1.1.1 staging.domain.com

4. Restart Apache

service apache2 restart

5. Setting up “staging.domain.com”

Create a new database for staging site.
After creating virtual host entry, go to- staging.domain.com and install the drupal site

Responses are currently closed, but you can trackback from your own site.

Comments are closed.