Drupal 8 Multi-Site and File Path Configuration Settings

So I'm finally getting the chance to build a Drupal 8 site that will be deployed to production. I'm going to use this opportunity to write a few blog posts about some of the interesting new changes in Drupal 8 I'm noticing as well as cover some of the exciting new features we've all been waiting for.

Drupal 8 Multi-site

The first thing I setup after installing Drupal is to create a site for each environment (i.e local, dev, and prod) in the sites directory. I went about this my usual way until I noticed a new file:

  • sites/example.sites.php

In Drupal 7 to create a new site in the sites folder, one would simply create a new directory named the same as the domain you plan on using, and Drupal would automatically know to look for the settings.php within that directory when visiting the site from said domain. So if you're local virtualhost is setup to use local.mysite.com, then Drupal 7 would automatically look for sites/local.mysite.com/settings.php and use those settings rather than some other environment. That's it, couldn't be simpler.

With Drupal 8 however, there is one extra step and this is where the sites/sites.php file comes into play. The sites/sites.php file is responsible for registering sites and mapping them to their respective directory. The comments in sites/example.sites.php explain in depth the purpose of this file and how to properly configure it for your needs. My needs are simple though, I'd like to simply have a site for my local and development environments while leaving the default for production.

In sites/example.sites.php you'll see the following section:

[image]

So I'll create a couple new sites by creating a sites/sites.php file and adding the following lines to the end of it.

[image]

When I try to access my site from the domain local.mysite.com, Drupal will use sites/local/settings.php before using sites/default/settings.php. I can now have per environment settings just like in Drupal 7. Another benefit of the new sites.php file is that one could have several domains mapped to the same settings file which was not possible in Drupal 7 without some strange workarounds. This new method is much more straightforward for this type of configuration.

Drupal 8 File Path Configuration

Another thing that stood out to me in Drupal 8 is the file path configuration. In Drupal 7 one was able to configure the paths to public and private files through the GUI which meant these paths were being stored in the database. In Drupal 8 however, the path to your public and private file directories is configured in the settings.php file, which is great because it forces versioning of this type of configuration in git.

[image]

After creating your local site, you'll notice that the site will by default store files in the files directory of your newly created site directory. This is generally what you want if you are running a truly multi-site installation, however, we're just piggy backing multi-site capabilites to create a local environment to develop in. Therefore, when we're developing, we would like uploaded files to live in /sites/default/files rather than /sites/local.mysite.com/files. To do this simply change this configuration in your sites/local.mysite.com/settings.php file like so:

[image]

So far other than these few differences the multi-site setup for Drupal 8 feels very much the same as the idea of per site configuration within the sites directory hasn't changed.

Tags: Drupal 8, Drupal