Multisite Local environment setup with Lando & Drupal

Multisite Local environment setup with Lando & Drupal

On30th Jul 2021, 2024-12-20T09:28:43+05:30 ByKarthik Kumar D K | read
Listen Pause Resume Stop

As we have seen in the earlier article to setup the Local environment with Lando & Drupal, Now let's see how we set up the multisite with the lando.

And hope you are already aware of Drupal Multisite. If not, It is a feature of Drupal that allows you to run multiple Drupal installs off of a common codebase. This allows you to share themes and modules between a collection of many websites. At a high level we can say Same Code with Different databases & Different Sites.

We already know Lando is a development tool (as discussed in an earlier article), which makes drupal development much quicker and easier. Lando provides an option to configure this from the .lando.yml file.

Let’s see in-details to set up a multisite. To setup Drupal multisite on lando you need to do below things:

In your .lando.yml you need to add proxies for each multisite in the appserver.

Have settings.lando.php file within your sub-directory (example: docroot/sites/drupal9_site_1/) which would need settings to connect to the respective database.

1. Changes in .lando.yml file

You need to add proxies for each multisite in the appserver.

proxy:appserver:- drupal9.site-1.local- drupal9.site-2.localservices:    drupal9_site_1:        type: mysql    drupal9_site_2:        type: mysql

2. Configure each settings.lando.php file

You need to have settings.lando.php file within your sub-directory & should add database connection settings on each file.

$databases['default'] = array (    'default' => array (        'driver' => 'mysql',        'database' => 'database',        'username' => 'mysql',        'password' => 'password',        'host' => 'password',        'prefix' => 'drupal9_site_1', // make sure host is matching with defined services above        'port' => 3306,    ));

In case, if you have huge number of multisites, You can have below code in the settings.php of default site.

if (@$_ENV['LANDO'] == 'ON' && file_exists(dirname(__FILE__) . '/settings.lando.php')){    require(dirname(__FILE__) . '/settings.lando.php');}

And include the below code in settings.lando.php

$sites['drupal9.site-1.local'] = 'drupal9_site_1';$sites['drupal9.site-2.local'] = 'drupal9_site_2';

And in each subsite’s settings.lando.php, have below code added.

$base_url = 'https://drupal9.site-1.local';

So, you will have both the base path and database creds in each of the subsite’s settings.lando.php file

$databases['default'] = array (    'default' => array (        'driver' => 'mysql',        'database' => 'database',        'username' => 'mysql',        'password' => 'password',        'host' => 'password',        'prefix' => 'drupal9_site_1', // make sure host is matching with defined service above        'port' => 3306,    ));$base_url = 'https://drupal9.site-1.local';

This way by configuring lando you can run drupal 9 Multisite on your local environment. And on the configuration front you can do many other things like adding a few more sites, having different configuration of each subsite as same as in default drupal etc.

Related Articles

Recent Articles

Recent Quick Read

Recent Great People

We Need Your Consent
By clicking “Accept Cookies”, you agree to the storing of cookies on your device to enhance your site navigation experience.
I Accept Cookies