DRUPAL MULTISITE: ALL YOU NEED TO KNOW

What is a multisite, why would I need it and why Drupal combined with Domain Access is the best option?

What is a multisite?

When I say multisite, I mean a website that consists of a single codebase and database but has the functionality to virtually create multiple websites. A visitor can then access these sites through different domain names, but in reality, they are all served from the same source. 

An example would be a company that has a corporate website and a separate website where they post vacancies within the company. Both sites have their domain name and, if necessary, their look and feel.

Multisite vs multidomain 

When you want to create multiple websites from one code base with Drupal, you have two options:

  1. Traditional multisite functionality: this is where you share the codebase (files for the core, modules and themes), but each site has its database. Having a multisite solution like this can be useful when you have multiple websites that have different needs. Think modules or a specific configuration. Because the database is not shared, each website has its content, users and functionality. 
  2. Multiple websites with the domain access module: with the "domain access" module it is possible to create different domains within your Drupal website. Each domain can be accessed through its URL. In this case, the database is shared, allowing you to share content and users between sites. In addition, if new functionality is created, such as a new paragraph type or a search API view, all sites can benefit from these enhancements.

I prefer the second option because sharing content, users and enhancements between sites is one of the things that makes a multisite solution great. So, when I talk about a multisite, I mean a multisite solution with Domain Access. 

Why would you want a multisite solution?

If you are tasked with maintaining multiple websites, which are more or less equal in terms of functionality, then a multisite is the way to go.

The advantages are:

  • Cost reduction. You only have to maintain one codebase. Bugfix updates on the multisite will automatically transfer to all other sites.
  • Easily share content, media and users between multiple sites.

The disadvantage is that when one of the sites produces an error, this is likely to be the case for all your sites. Also, when the database is shared, it means that if one site is hacked, they all are. This is why it is important to keep your Drupal code up to date and always install security updates as quickly as possible. 

How does creating a multisite setup with Drupal work?

I won't do an in-depth tutorial for now, but I want to give you an overall impression of the steps you need to follow to create a multisite with Drupal.

  1. Install the domain access module.
  2. Create one or more domain records.
  3. Each domain record can have its domain name (or URL). For example, the corporate website can be located at www.company.com, while the job-specific site can have www.jobsatcompany.com. It is also possible to work with subdomains such as jobs.company.com.
  4. You can now create content (nodes) or users and assign them to one or more domains.

A practical example of how you can use Drupal's multisite functionality

Suppose you have a multi-site setup with a dedicated domain for a corporate website and an additional domain for job postings. Both websites need an overview of the latest news. Here's how to accomplish this with Drupal and Domain Access:

  1. You create a 'News' page and assign it to both domains. 
  2. Include a menu item on this page in the main menu. Because the 'News' page is assigned to both the company and the jobs site, the menu item will be visible on both sites.
  3. Create a block with views showing all news. Within this view, you can filter the news by active domain. 
  4. Publish this block on the 'News' page created in step 2.
  5. Create some news and assign them to the corporate or work site.

Depending on the domain or site you are viewing, this newly created 'News' page will only show the items assigned to this domain. This way, you can share features such as a news summary page between multiple sites. You only have to create the view once. In this example, it is also possible to publish a news item on both domains. This will ensure that the article is available on the news page of both sites.

As you can see, using Drupal and Domain Access to create a multisite can save you a lot of time.

Reusing a theme for multiple sites

Another interesting thing about using a multisite solution with Drupal and Domain Access is that you can easily reuse a theme. So, you can use the same theme for your corporate and jobs website. Both sites will benefit from all the improvements you make to this theme.

You can also use a different theme for a specific domain or site. But what's even better is that you can create a sub-theme. Say, for example, you want your corporate website to have a header with a red background, but you want the header of your careers website to have a blue background. In this case, you can create a sub-theme for your jobs website and just override the CSS rule that specifies the background colour of the header. If you make a change to the main theme, this will also be visible in the sub-theme, except for the CSS rules that are overwritten. Giving you the advantage of having to maintain a theme, but still enough freedom to adjust where necessary for other sites.

The disadvantage of creating a multisite with Drupal

When you choose to create a multisite solution with Drupal and Domain Access, there is one major disadvantage. And that is module compatibility. In some cases, you want to share functionality between sites, but both need their values. If a module is not compatible with Domain Access, it won't be possible to enter specific values for individual domains. 

A real-life example I have encountered is trying to create an XML sitemap for multiple domains.

There are two modules available that can create an XML sitemap for your Drupal website. But in both cases, I couldn't get them to work the way I wanted them to. Ultimately, I created separate RSS feeds that contain all the content from different sites filtered by the domain that is also accepted by services like Google Search Console.

Save time and money by easily creating multiple websites

A multisite solution built with Drupal and Domain Access has many advantages. You can easily create a new website and share content and users between different domains. You just have to keep a Drupal installation up to date. But make sure you do, because if your Drupal is insecure, all your sites are vulnerable. It is also possible to share functionality between sites saving time by recreating it in each different Drupal configuration. The biggest drawback is third-party module compatibility. This may force you to be creative in finding a solution or have to do without desired functionality.

Do you have any questions on how to build your multisite with Drupal? I have created several Drupal multi-sites. Some of them with more than 160 subdomains/webs that could share content.

Have Any Project in Mind?

If you want to do something in Drupal maybe you can hire me.

Either for consulting, development or maintenance of Drupal websites.