, ,

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!

,

Troubleshooting Slow Sites

Part of supporting online projects comes with the territory of troubleshooting slow websites. Sometimes it can be hard to know where to turn when you’re met with a “My site is slow!” support ticket– especially if the site is loading quickly on your end.  This post covers tips & tricks for figuring out those red flags that may make a site run slowly. And while the list below may not hit on every issue that will come up, it’s a great checklist to use as a starting point.

Recreate the Speed Issue

Doublecheck that this isn’t an issue with the user’s internet, and that the site is indeed having load issues. (You can always have the user test their internet connection speed here or here.)

WHM: Check the Load

^The green box referenced above. If that load begins with anything less than “5-8.” you’re in the clear and this is likely not a server issue. If the load starts getting into the 14s and 15s or higher, this issue may be greater than the single site.

WHM: Check Apache Status

Search ‘Apache’ in the top, left-hand corner and click Apache Status.

Apache handles all processes on the server and is currently set to handle up to 150 requests at any given point. If the number of processes crosses this threshold and Apache maxes out, that could definitely be the smoking gun for slow-moving sites.

WHM: Check MySQL

Search ‘mysql’ in the top, left-hand corner and then click Show  MySQL Processes.

^This list should generally be pretty small. If you see a full list like the one above where a single database is running a ton of processes, that should be your pointer that this is a site issue, not a server issue.

File Manager: Check Error Logs & Plugins

Every time you install a plugin in your dashboard, you’re asking your site to load another set of processes in your database. So naturally, if you’ve got 20+ plugins installed on your site, chances are that could be leading to slowness.

Likewise, plugin/theme/software conflictions are real, so checking the user’s error_log in their File Manager can be helpful in determining what’s going on.

You can ask the user to turn off all of their plugins, and then activate them one by one to figure out which plugin(s) may be causing the slowness. And if that’s not possible for the user…

phpMyAdmin in cPanel: Plugin Database Tables

If the site has a ton of plugins and you’re trying to figure out which one may be leading to the slowness, have a look at the database tables associated with each plugin.

Note that sites won’t function properly if one table is unusually massive. The rows column is associated with the number of entries on a given table. As you look at the screenshot above, notice that the database table called wp_prli_clicks (part of a Plugin called Pretty Links that can track site clicks) has over 58,000 entries of stored data. Yikes! So sometimes even if the plugin is working correctly and not conflicting, the user’s specific settings can be causing slowness.

phpMyAdmin in cPanel: Transient Rows

Transient Rows are essentially cached database queries that can be found on the last page of the wp_options table in phpMyAdmin. You won’t hurt anything by deleting transient rows. And depending on how many there are, deleting these might actually help speed up your site!

To delete these rows, copy the following SQL commands:

DELETE FROM `wp_options` WHERE `option_name` LIKE ('_transient_%');
DELETE FROM `wp_options` WHERE `option_name` LIKE ('_site_transient_%');

Click on the SQL tab in the wp_options table and paste the commands. Click go.

Query Monitor Plugin

And if all else fails, installing the Query Monitor Plugin on the WordPress dashboard has proven to be a helpful troubleshooting method for us in the past. This debugging tool shows you what might be going on by listing the queries on the page that you’ve loaded, and highlights any issues as they occur.