Setup Drupal 9 Multisite on a web server, along with a local development copy

My process for setting up a Drupal multisite environment.

This article is a work in progress.

It doesn’t matter which version is created first, local or remote, but we start with the remote version.

Create Drupal Multisite on the web server

Create databases

Create the databases via cPanel.

Install Drupal 9

SSH to the web server and navigate to the intended installation location (typically the domain folder).

# download and unzip the latest Drupal version
unzip zip

# move the folder to the root install location
mv -f drupal-9.x/{.,}* /home/username/

# create the settings.php file
cp sites/default/default.settings.php sites/default/settings.php 
chmod a+w sites/default/settings.php 
chmod a+w sites/default Code language: PHP (php)

Visit the URL and complete the wizard, using the already created databases. Add a database prefix, such as ‘drp_’.


Enable Multisite

# Create the sites.php file
cp sites/example.sites.php sites/sites.phpCode language: PHP (php)

Create additional site

Add the following to the bottom of sites/sites.php

$sites[''] = '';Code language: PHP (php)

Create a folder and settings.php for the site.

mkdir sites/ 
cp sites/default/default.settings.php sites/ Code language: JavaScript (javascript)
  1. Create a subdomain the site (could also an add-on domain)
  2. Delete the folder that was automatically created
  3. Create a symbolic link in its place
# point the additional site to the root of the root site
ln -s ~/
# removing a symbolic link
unlink <path>Code language: PHP (php)


Create a local development copy

Export Drupal

Export a copy of the database into a folder in the Drupal installation folder, which will become part of the Git repo.

mysqldump -u username -p <db_name> > database/<db_name>.sql Code language: HTML, XML (xml)

Create a Git repo, adding all files and folders in the Drupal root.

Import Drupal

Download the repo, and rename folder as desired.

Edit settings.php for each site.

$databases['default']['default'] = array (
  'database' => 'localdb',
  'username' => 'root',
  'password' => '',
  'prefix' => 'drp_',
  'host' => '',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);Code language: PHP (php)

Import the site via devdesktop, specifying the folder location and using the exported SQL dump file.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.