Using drush command line with Drupal multisite.

Using drush command line with Drupal multisite.

Few tips and tricks running Drupal multisite (for both Drupal 7 and Drupal 8).
Vladimir Roudakov


Drush is a command line tool that Drupal develops used for years. Drush allows you to control your Drupal instance from site installation to minor tasks brought by specific modules.


Drupal multisite is Drupal mode where 2 or more websites are sharing same Drupal core and possibly various Drupal extensions (themes, modules, libraries) or can have their own variations.

One of the good multisite examples is where you have various vendors with some common functionality and some vendor specific functionality e.g. and


sites.php file is located in <root>/sites/sites.php (or can be copied from <root>/sites/examples.sites.php template). It contains all the data required to define multisite.

Let's say, you have 2 websites in your <root>/sites/ folder site1 and site2. Let's say you have few environments for each site with the following URLs:

  • Local: site1.local and site2.local
  • Development: and
  • Production: and

So your sites.php files would look like this:

$sites = [ 'site1' => 'site1', 'site1.local' => 'site1', '' => 'site1', '' => 'site1', 'site2' => 'site2', 'site2.local' => 'site2', '' => 'site2', '' => 'site2', ];

In the end we have all possible URLs on the left and existing folder on the right.

Drupal 8

Now, to target specific website in Drupal would you use -l flag in drush.

For example to clear all cache on site1 run

drush -l site1 cache:rebuild

To update database on site2 run

drush -l site2 updatedb

Drupal 7

For Drupal 7 drush requires both -l and --root parameters to work correctly for multi site e.g. If your drupal is installed in web (default on hosting) folder you'd run the following to clear cache on site1:

drush --root=web -l site1 cache-clear all

If your drupal is installed in docroot(default on acquia hosting) folder you'd run the following command to update database on site2:

drush --root=docroot -l site2 updatedb


Note that some of the commands on drush 8 (last version supported for Drupal 7) and drush 9 (latest version for Drupal 8) use different syntax so you might hear to drush commands to familiarise yourself with version you are using.

Happy coding.