Using Drush to administer multisite
One of the admiring features about Drupal is its ability to leverage single code base to power a stack of sites. Drush the excellent command line utility eases the work of administering Drupal sites.
Our recent work raised a question, will these two blend & work together?
Of course we tried this, the answer is yes but to be used with more caution!!
In case of Drupal multisite, Apache (or any Web server) is configured such that more than one domain name points to same document root. Drupal by identifying the request originating domain and folder structures loads the respective modules/themes & database. Drush utilizes the similar approach.
In case of multisite, to run a drush command against a specific site/database there are two ways,
1. Switching to respective site folder
In this case cd to the site folder. Ideally from inside the folder sites/one.example.com or similar the drush commands to be issued. This will run all the commands against one.example.com site.
Assume multisite setup with separate database per site. Then
$ drush sql-connect
user@hostname:/var/www/sites/one.example.com$ drush sql-connect mysql --database=example_one --host=localhost --user=example_one --password=example1
2. Passing additional argument to drush commands
This works by passing argument -l (or --uri). The request originating domain is mentioned explicitly here and hence takes more precedence over #1.
user@hostname:/var/www/sites/one.example.com$ drush sql-connect -l http://two.example.com mysql --database=example_two --host=localhost --user=example_two --password=example2