Set up multisite in lando for shared hosting

If you're building sites for different clients, you usually want a custom codebase and server for each. However if you have a client with multiple websites, or want to put together a platform with common code that can be extended per site, you can do a multisite. This lets you use one Drupal codebase for multiple websites.

Usually when you set up Drupal, you use the /sites/default directory. To set up a multisite, add a directory to /sites for each additional site you need. Configure the url and where to redirect it in sites.php.

One trick for lando is using proxy urls to your appserver to map to the directories in sites.php. I created sub domains like sub.main.lndo.site, which is working out fine.

 

To add a new site to lando:

  1. Add the proxy and database service in .lando.yml.
  2. Rebuild lando to update the proxy and services.
  3. Create the directory in /web/sites/SITE.
  4. Update /web/sites/sites.php with the new url and directory.
  5. Go to the new URL /core/install.php OR copy a settings.php file and update the credentials.

 

To add a new site in CPanel:

  1. Set up the new domain and subdomain.
  2. Replace the default root directory with a symlink pointing to the multisite web directory.
  3. Create a database and password using the mysql wizard.
  4. Visit /core/install.php and install the site.

 

To move existing sites into the multisite, add it's modules to composer.json and move the site directory. You may need to test the new module/drupal version before applying.