3

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.

6
  • Did you check drushcommands.com/drush-8x/core/site-install?
    – Jimmy Ko
    Commented Aug 3, 2016 at 23:15
  • Where on that page does is say anything about multisite installation? - Gil
    – gilmarks
    Commented Aug 3, 2016 at 23:27
  • You can specify the --sites-subdir which will create a separate folder for multi site
    – Jimmy Ko
    Commented Aug 3, 2016 at 23:29
  • Which is mentioned in the link I already provided, said I read, and questioned further. If you have a concrete example, great. Just saying "look over there somewhere" doesn't help.
    – gilmarks
    Commented Aug 3, 2016 at 23:31
  • 2
    I am not making fun, I just want to ensure how much you know and how further I can provide. No offence.
    – Jimmy Ko
    Commented Aug 3, 2016 at 23:35

1 Answer 1

5

In the link you provided, @greg_1_anderson mentioned using --sites-subdir. This option is used to create a site folder under <DRUPAL_ROOT>/sites/.

For example, if you run drush si --sites-subdir=example1.com, it will create a example1.com folder under <DRUPAL_ROOT>/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
1
  • 2
    Splitting hairs, since the OP wants to enter a single line, just put the commands in a single line, separating them with ; or &&.
    – avpaderno
    Commented Aug 6, 2016 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.