Just another 陰陽 site Drupal 9 Multisite setup in Lando


Drupal 9 Multisite setup in Lando The multisite feature in Drupal allows to effectively create and manage a fleet of websites where all the sites will share the same codebase while having separated databases, configurations, and assets. In this post, we will see how to setup a Drupal multisite setup locally using Lando with an assumption that you already have a master site setup using drupal9 recipe. 

Setup sites for multisite

The first thing we need to do is to configure the sites that we need. In this case, let’s call the master site as the main site and the other 2 sites which we will create are mojave and yosemite

Step 1: Create the folders for the sites in web/sites/* directory

Step 2: Copy the default.settings.php from web/sites/default to the multisite directories as settings.php

Step 3: Copy the default.sites.php to sites.php and add entries for each of the multisite to make the main site aware of the sites.

// @codingStandardsIgnoreFile
$sites[''] = "mojave";
$sites[''] = "yosemite";

Add db services to Lando file

Now that our files are setup, we will need databases for each of the sites. This will be handled via Lando by update the .lando.yml file to add each database as new services.  

Note: We don’t need to add the database service for the main site since it will use the default database service.

  # The database service used for the `main` site.
    type: mariadb:10.4
    portforward: true
      user: drupal
      password: drupal
      database: main
  # The database service used for the `mojave` site.
    type:  mariadb:10.4
    portforward: true
      user: drupal
      password: drupal
      database: mojave
  # The database service used for the `yosemite` site.
    type:  mariadb:10.4
    portforward: true
      user: drupal
      password: drupal
      database: yosemite

Add proxy for site domain

Lando uses Traefix as a reverse proxy to make the routing and have clean URLs to  point various ports inside of various services. So, by default if the app name is set to drupal, we will get a nice URL like

Now, to add the URLs for the other two sites we need update the .lando.yml file to make an proxy entry for each sites. Alternatively, you can update the default URL for the main site as well.

Note: The proxy URL must match the domain entered in the sites.php file.


Install the sites via UI

Now that the multisites are configured, we can start installing Drupal on each of the site. Below is the table to map the domain and database credentials for each site.

Site URL DB Username DB Password DB Name
Main drupal drupal main
Mojave drupal drupal mojave
Yosemite drupal drupal yosemite

If, the files directory is not created automatically then you will need to create one for each site and give the appropiate permissions for the directory.

Install the sites via Drush Aliases

Although, the sites are accesible via UI and browser, Drush access and setup is also important for development and deployment purposes. For this, we will need to setup the Drush aliases for each site so that we can access the sites right from the terminal.

Setup Drush aliases

To setup the Drush aliases, create a *.sites.yml file in the PROJECTROOT/drush/sites/ directoryIn our case, we will create a file called drupal.sites.yml with the following content.

# The uri key should map to the proxy domain names 
# being setup in the .lando.yml file.
 root: /app
 root: /app
 root: /app

Once, this is is setup you can access the sites using Drush aliases. To check the aliases list run lando drush sa whcih should give

  root: /app
  uri: ''
  root: /app
  uri: ''
  root: /app
  uri: ''

So, to access the “mojave”  site you can run lando drush @drupal.mojave status

Site Installation

Now, that the Drush aliases are setup we can install the sites using the Drush site-install command and passing the sites directory name as the option.

# To install the main site
drush @drupal.main si --sites-subdir=default -y

# To install the mojave site
drush @drupal.mojave si --sites-subdir=mojave -y

# To install the yosemite site
drush @drupal.yosemite si --sites-subdir=yosemite -y

Verify site settings & configuration

Once, the sites are installed & setup we can verify if the configurations and data is isolated for each site. To check enable different themes for each site, enable different modules and/or create few dummy contents for each site. You will notice that each of the sites configurations are not isolated. However, we would also like to use Drupal Configuration management for each site but that can be a separate post by itself.


To add a new multisite

  1. Create a new directory under web/sites by the name of the site
  2. Copy the default.settings.php from web/sites/default to the multisite directories as settings.php
  3. Update sites.php to make an entry for the new site.
  4. Add a new service to Lando file for the new site database
  5. Add a new proxy for the new site in the Lando file
  6. Run lando rebuild to create a the new database and update proxy
  7. Add new entry in the *.sites.yml for Drush alias
  8. Install the site either by UI or using Drush alias.

Sat, 05/01/2021 – 20:30

Drupal development

Go to Source