I'm using Drush 9. With the old drushrc.php I could easily include a local.drushrc.php that dynamically set the site url. How can I do it now?

This is similar to How can i set site url dynamically in Drush-9?. However I don't want to pass the url in every Drush command. I think of something like below in ../drush/drush.yml:

      - ${env.home}/local.drush.yml

But I'd need another variable that point to the Drupal site directory (sites/default in a monosite, sites/CURRENT-SITE in a multisite). Does such a variable exist?


Reading https://github.com/drush-ops/drush/blob/master/examples/example.drush.yml it seems you can put a site specific drush.yml in a sites directory. It is merged with the global file(s).

PS! I haven't tested this myself.

  • 1
    Tested but it didn't work. I agree that it should have worked. – jcisio Jun 29 '18 at 6:49
  • Try checking your own example.drush.yml file in case you have an older version. The local config filename used to be different. – Andy Jun 29 '18 at 9:14
  • I'm already on Drush 9.3.0. The file sites/default/drush.yml is not automatically detected. I thought this was a problem with lightning, but I try with a standard distribution and I have the same result. – jcisio Jul 5 '18 at 13:35
  • Confirming that I'm on Drush 9.5.2 and the documentation suggests that the first place it checks is sites/default/drush.yml but this doesnt seem to be the case, because it is not picking up the default --uri option i have configured in that file options: uri: http://mysite.test when I run drush uli. Not sure what's wrong. – JamesWilson Oct 26 '18 at 16:41
  • 2
    Ok, I've figured this out: For sites/default/drush.yml to be recognized by drush you have to run drush from the drupal root folder. This used to not be a problem in drush 8 with sites/default/drushrc.php – JamesWilson Oct 26 '18 at 17:40

Here's what I do on my sites and it works:

Step 1: sites/default/drush.local.yml

  uri: 'https://dev.example.com'

You can name this file however you want. Also, since this file varies from env to env, I ignore it with .gitignore. At the same time, I commit an example.drush.local.yml.

Step 2: drush/drush.yml

  • One level above Drupal installation, .i.e. where Drupal's index.php is located, I have my composer.json and vendor directories.
  • In this directory, I create a directory named drush and in it, I place a drush.yml with these contents:
      - web/sites/default/drush.local.yml

After this, I running drush st from that directory, will show you that the drush.local.yml has been detected and the site URI is set correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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