Creating a Drupal Multisite

Up until some time last week, I didn’t actually realize that a Drupal Multisite was possible. I received a support ticket asking if Drupal Multisites doable in Reclaim Hosting’s environment, and responded by saying something along the lines of, “well since single Drupal sites are possible within Reclaim, I would imagine a Multisite is as well, though I don’t have much experience with it”. I don’t like responding that way. So I made it my mission to set one up! (Spoiler: Drupal Multisites are, in fact, possible at Reclaim.)

Contents

  • Why Drupal Multisite?
  • Getting Prepared
    • Naming our sites
    • Deciding where our sites will live
    • Set up databases
    • Create subdomains (if applicable)
  • Installing and Configuring Drupal Sites
    • Download Drupal software & upload to account
    • Creating sites.php
    • Making sites directories
    • Copying over & renaming necessary files
    • Creating Files directory
    • Create a symbolic link with cPanel’s directories
  • Drupal Site Setup Wizard
    • Follow the prompts
    • Run a FixPerms script

Why Drupal Multisite?

If you’re familiar with a WordPress Multisite, a Drupal Multisite will sound very familiar. A Drupal Multisite allows single, independent Drupal sites with separate users to run on a singular codebase with shared modules. For more information, head here.

Getting Prepared

  1. Start first by deciding where you want your sites to be called and where you want them to live. I’m going with a fruit theme today, so one of my sites will be called Apple and the other one will be called Orange. Drupal Multisite allows you to set up subdomains (site.drupal.com) or subdirectories (drupal.com/site). I’ve always thought subdomains are a bit cleaner so I’m going to use subdomains off of my brumface.com domain. If you want to use subdirectories, this guide will still apply.
  2. Before even installing Drupal software, I’m going to go ahead and create a database for each site in my cPanel. (For more info, read our guide on database management.)

-For this step, you’ll want to go to cPanel > MySQL Databases, name your database, and click create.

-Repeat this process for your second site. I called mine labrumfi_orange.

-Now we’re going to create a database user that will be assigned to both of these sites. If you go to cPanel > MySQL Databases and scroll down past your current databases, you’ll see a section where you can add new users:

I called my database username labrumfi_drupal. Set a secure password with the Password Generator and click Create User. (P.s. You’ll need these credentials later on!)

-After creating the database user, we need to assign it to our two databases. This can also be found on the cPanel > MySQL Databases page:

^Select the user and database you just created and click Add. On the following page, you’ll be asked to manage user privileges. Select All Privileges, scroll to the bottom, and click Make Changes.

-Repeat this for your second site. So since I just added labrumfi_drupal to my _apple database, I’m going to now add the same user to my _orange database. When complete, your database section should look something like this:

3. Now that that piece is done, we’re going to create our subdomains under cPanel > Subdomains. If you’re using subdirectories, skip this step. This part is pretty self-explanatory, so for the purposes of keeping this particular tutorial as short as possible, I’m going to point you to this guide on creating subdomains in cPanel. The subdomains I created were apple.brumface.com and orange.brumface.com.

^Note that I took public_html out of my document root. I’ve found that the simpler you can make your locations, the better. But that’s just personal preference.

Installing & Configuring Drupal Sites

  1. Head to drupal.org/download and download a .zip file of the latest version of Drupal.
  2. Go to File Manager and create a new folder directly in your /home directory called drupal. Upload the Drupal .zip file and extract it. Your drupal folder should now look like this:

^All of our drupal files are located inside the drupal-8.5.5 folder. We need to pull them out into the main /drupal directory. From there, you can delete the empty drupal-8.5.5 folder.

3. Now that we’ve got our files in the right place, we need to let Drupal know that we’re going to be working with more than one site. We do this by going to drupal > sites and create a sites.php file. For an example of what to add to your sites.php file, open example.sites.php. I’ve also included instructions below:

Create a sites.php file with the following text:

<?php

$sites = array(
//https://apple.brumface.com
'apple.brumface.com' => 'apple', 
//https://orange.brumface.com
'orange.brumface.com' => 'orange'
);

In the above example, replace ‘apple.brumface.com’ with ‘yourfirstsite.domain.com’, and replace ‘apple’ with ‘yourfoldername’. Repeat for the second site.

Note: If you’re using subdirectories (for instance, domain.com/yourfirstsite) the array would look like this:

<?php

$sites = array(
//https://brumface.com/apple
'www.brumface.com.apple' => 'apple',
//https://brumface.com/orange
'www.brumface.com.orange' => 'orange'
);

Make sure to save changes.

4. Ok, hang with me now- we’re going to do a little SSH action. Its simple enough, but if you need a refresher on logging into your account via terminal, I’ve added a screenshot of my login below. (You can also use the terminal function in your cPanel!)

ssh cPanelusername@server.reclaimhosting.com

^when prompted for a Password, enter your cPanel/FTP password.

-Once in terminal, navigate to /drupal/sites

For the commands below, replace ‘apple’ and ‘orange’ with your ‘site1’ and ‘site2’:

mkdir apple
mkdir orange
cp default/default.services.yml apple/services.yml
cp default/default.services.yml orange/services.yml
cp default/default.settings.php apple/settings.php
cp default/default.settings.php orange/settings.php

^With the above commands, we created our apple and orange directories and then copied and renamed the default files (default.services.yml and default.settings.php) into each one. Now when I refresh in file manager, I see the following:

5. We also need to add an empty ‘files’ folder in both in both our apple and orange directories. The ‘files’ folder will be filled during the Drupal Setup Wizard installation process further down. Feel free to create these folders in terminal or in file manager.

6. There’s one final step. When we create a subdomain in cPanel, cPanel creates a folder in File Manager for them by default. (Remember when I set my document root outside of public_html?) But since we just made our own directories within the sites folder, we have to create a symbolic link from cPanel’s default directories with our correct directories. It’s weird, I know.

ln -s drupal apple
ln -s drupal orange

Now when we navigate to apple.brumface.com or orange.brumface.com in our browser, we see the following:

Drupal Site Setup Wizard

If you need assistance with the Drupal Setup Wizard, here is a list of the settings that I used:

Language: English
Profile: Choose Standard Installation
Requirements: Run a Fix Perms script if needed
Database: Choose MySQL, MariaDB, Percona Server, or equivalent; enter the database information that you created earlier
Install:

Configure Site: Set your site information

If you stuck with me this long, congrats!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top