How do you use 'drush site-install' to install a multisite with separate databases using a single command? I regularly use drush site-install to install single Drupal 8 sites from the command line. It works great.

I'm now working on building a Drupal 8 multisite. It'll have separate databases per site.

Can drush si be used to install a multisite from the command line? Does it use Drupal8's sites.php?

I saw Need Steps to Install multisite configuration using only drush. i.e multi-site install having different database, but I'm not clear on what's actually done there.

I figured it should be able to, but I can't find any HowTo docs for multisite.
In the link you provided, @greg_1_anderson mentioned using --sites-subdir. This option is used to create a site folder under &lt;DRUPAL_ROOT&gt;/sites/.

For example, if you run drush si --sites-subdir=example1.com, it will create a example1.com folder under &lt;DRUPAL_ROOT&gt;/sites/, settings.php will also be generated in this folder. It contains the database configuration.

Since it is a multi site structure, you may not want to share the same database. You have to specify the database information with --db-url.

For example:


DB: MySQL
root username: username
root password: password
host: localhost
table name: example


You can specify above information with --db-url=mysql://username:password@localhost/example.

A more complex example involving setting more sites for a multi-site configuration could be the following.

drush si --sites-subdir=example1.com --url=mysql://username:password@localhost/example1
drush si --sites-subdir=example2.com --url=mysql://username:password@localhost/example2


Moreover, if you want to have different database credentials for different sites, you can dynamically create the separate username and password at the same time.

drush si --sites-subdir=example1.com --url=mysql://user1:newpassword1@localhost/example1 --db-su=username --db-su-pw=password
drush si --sites-subdir=example2.com --url=mysql://user2@newpassword2@localhost/example2 --db-su=username --db-su-pw=password