Skip to main content

Drupal Multisite - Multiple Sites on Drupal in a Nutshell

Category: 
Updated: 
Reading time
: 8 min

Drupal stands out among the best solutions for business. Yet how to make it work for larger companies that need to manage many complex sites simultaneously? The answer is Drupal multisite. Learn how to use it by reading this article. We also prepared something for developers.

Drupal Multisite - what do you need to know?

What is Drupal multisite?

At its shortest, a Drupal multisite (also referred to as a Drupal multi-installation) consists of multiple sites combined in a single Drupal installation. Each site is located in a different folder of the platform's system directory and has separate settings.php and database files associated with it. Of course, the sites have different web addresses and may have other content - all depends on your needs.

Drupal multisite - how does it work?

In Drupal multisite, sites share:

  • the same version of Drupal core,
  • the available modules,
  • the available themes,
  • the base code.

At the same time, the sites do not share:

  • the domains,
  • the URLs,
  • the databases,
  • the enabled modules,
  • the enabled themes,
  • the configurations,
  • the user profiles,
  • the content,
  • the files.

With such a structure, it is possible to create a set of pages conveniently created, managed, deployed and updated from a single location, yet vary in content and design.

Advantages of Using Drupal Multisite

The fundamental reason for using Drupal multisite is to save time when managing many Drupal sites. That is because each time a new Drupal update is released, it only needs to be carried out on a single code base.

The benefits of such an installation are apparent not only at the site management stage but also during site creation. That is because, in the case of Drupal multisite, it is sufficient to design a main basic theme. Then, the theme's inheritance mechanism will allow you to pass this foundation on to subsequent projects so that you can quickly move on to working on unique features for them.

Drupal multi-installation also offers long-term benefits. It helps reduce and pay off future technical debt when companies make shortcuts to achieve their plans. Such decisions are often unavoidable. The problem arises when technical debt becomes too large. As a result, it becomes increasingly difficult to maintain sites and make major edits. This is because of legacy code which is different for each website.

Websites running on Drupal multisite have less of a technical debt problem and are of better quality than many websites put up separately. This is because the solution saves resources that would otherwise have to be used, for example, on hiring an agency to create another project. When laying the foundations for a multisite project, developers will also make more of an effort to prepare flexible and sustainable solutions when they realize that putting in the necessary effort in this area will pay off in the future.

Business and Technical Advantages of Drupal Multisite

Business AdvantagesTechnical Advantages
Flexible solution – if your development team knows that a given template/module will be used on many subpages, they immediately start working on configurable solutions.One code base for all websites – updates introduced on one page are immediately available to all Drupal sites using that feature.
Cheaper upgrades – new functions or updates are prepared only once and can be implemented on all pages at the same time, instead of preparing them separately for each page.The option to add modules to one or several installations – although this is a multisite, you can add extensions (including custom ones) that will not be available on other pages.
Ease of editing – an employee who manages one site will be able to publish content on other pages as well.Launching subsequent websites is faster and cheaper – with a properly prepared base template, configuration usually comes down to switching a few settings and enabling selected functions.
Savings – since multisite has one code base, all pages can be maintained by one development team.More testing options – with a single code base, you can spend more time on extensive tests, code reviews, and reducing technical debt while meeting deadlines.
Standardization – a common function database makes it easier to maintain a high level of content creation and modification on all pages within a multisite.Faster deployment of security updates – similar to adding new features, a security update is prepared once and deployed to all Drupal sites at the same time.

Disadvantages of Drupal multisite

Drupal multisite is not the best option if the sites you intend to serve will differ significantly in functionality and design. Of course, such an endeavour is possible, but you will spend too much time struggling with the platform itself rather than unleashing its full potential.

Another issue to keep in mind is security. If any problems arise on one site, they might affect the rest of the related sites. Similarly, the consequences of errors made during installation or upgrades will have wide-ranging implications.

Drupal Multisite – Types of Installation

There are several ways to design a Drupal multisite architecture.

  1. Classical multisite approach

    The classical multisite approach requires:

    • Drupal file structure knowledge,
    • indicating the target domain,
    • an entry in sites.php that directs to a specific website folder,
    • creating a database.

    This approach looks similar to what we discussed earlier – with separate configurations, databases, etc. However, the code base is the same. To add a new element to each multi-installation, specialists use configurations exported to an yml text file. They can also use the Configuration Split module. It allows for segregating configurations – choose which ones are to be shared and which ones are only available to a selected website.

  2. Multi-Domain Architecture

    This model is similar to the one described above. The difference, however, is that all pages share a common database. This is where the Domain module comes in handy, as it allows numerous pages to be managed. This design makes updating individual pages less of a hassle. The disadvantage, however, is that adding separate functionalities to individual sites is much more difficult. Therefore it is a solution suitable for similar sites.

Drupal Multisite – Implementation Challenges

Drupal multi-installation has many advantages, yet its implementation might be a bit tricky. Here are the challenges you might face.

First Configuration

If you want to use multisite, you have to be aware of the higher implementation costs. All work on the multi-installation depends on this point. Therefore, it is worth planning everything before starting the configuration. This will allow you to assess whether the site is suitable for multi-installation and prepare for changes in the configuration files. Will using the config_split module be necessary, or will the config_ignore be enough?

Remember that Drupal custom modules must support all instances of multi-installation and be updated to maintain compatibility. Preparing a global settings.php file in which you define variables dependent on each is a good solution.

User Management

Each instance has a separate database when the installation does not use the Domain module. This means each website has separate user accounts, which is sometimes desirable. However, in some cases creating users and managing their permissions becomes problematic. In such situations, CAS (Central Authentication System) tools come to the rescue. Drupal has modules for integrating applications with CAS that facilitate importing user names in bulk. The module should be configured in a way that anyone from a given CAS domain can log in and create an account on the first visit.

Multisite Configuration

  1. Installing New Instances

    When creating a single Drupal website, the files are located in the sites/default folder. You do not have to worry about the sites/sites.php file, because all traffic is directed to the default folder. To add a new instance, you can use Drush and execute the command:

    drush site-install standard --sites-subdir=new_site --account-name=admin --account-pass=admin_pass --db-url='mysql://user:password@localhost/db_name'

    The command creates a sites/new_site folder and the configured settings.php with the specified database access. The script automatically installs the basic configuration and creates the ‘admin’ user.

    Remember to set the domain correctly – the vhost should direct to the same place as the first domain, and Drupal needs to be shown which domain will direct to which installation folder. To do this, add a line of code to sites/sites.php:

    $sites[‘new-domain.com’] = ‘new_site’;

    After doing so, by entering new-domain.com, you will see your new website.

    Multiple websites configuration
  2. Sharing Configuration

    You can use the same yml configurations if your Drupal sites are identical, Simply set the same path to the configuration folder in the settings.php files, e.g.:

    $settings['config_sync_directory'] = '../config/sync/multisite/';

    You can use the config_ignore module to exclude parts of the configuration from export/import. In its configuration, you provide entire configuration files or you can exclude a single definition from the file. For example, if you want to exclude your name from exporting to yaml files, add the following path to config_ignore:

    system.site:page

    The path includes the configuration name ‘system.site’ and the specific argument you want to ignore.

  3. Partial Configuration Import

    If ignoring files is not enough for you, you can use the config_split module. It allows for creating separate sets of configurations that can be activated or deactivated. For example, you can define one split for the development environment that contains debugging configurations, and another for the production. Likewise, one set for page_one and another for page_two. When the Config Split module is activated and configured when exporting Drupal configurations using Drush or the UI, the configs assigned to a specific split are excluded from the primary export and saved in a separate directory. When importing a configuration, you can decide which split to activate. This way, you can load only those configurations relevant to your instance. This allows you to adjust your application without manipulating configuration files. The module allows you to set priorities for different splits. In situations where different splits have conflicting settings, the order in which they are applied determines the final configuration.

Drupal Multi-Installation - Summary

Drupal multisite is a great solution that works well for businesses running multiple websites simultaneously. By investing in a multisite, you can significantly reduce the time spent on managing your Drupal sites and, in turn, save a lot of money. So consider the benefits of this solution when setting up multiple sites for your business.

Rate entry
4.7
Rate:  4.7 Amount of votes:  21

Thank you for rating the post!