Score:0

Why do some Drush commands only run from docroot?

us flag

Wondering if anyone knows why some Drush commands (with file parameters) only run from the docroot and won't run from the project/composer root?

Commands such as drush sql-query and drush locale-import are among these.

For example, with standard Drupal folder structure:

/ (composer root)

  • composer.json
  • vendor
  • translations
    • translations.fr.po
  • web (docroot)

running from composer root:

  • vendor/bin/drush locale-import fr translations/translations.fr.po

gives file not found error. Even using ./translations/translations.fr.po gives same error

but going to docroot and running:

  • ../vendor/bin/drush ../translations/translation.fr.po

works fine.

Our deploy scripts always run composer, drush and other commands from the composer root folder. So a bit of a pain to have to cd /web and then cd .. for these couple "special" Drush commands. Guessing there must be something I am doing wrong.

cn flag
IIRC Drush commands tend to run with the web root (not execution path) as the working directory - does `vendor/bin/drush locale-import fr ../translations/translations.fr.po` from the project root work?
leymannx avatar
ne flag
It might depend a on the version of Drush and the composer.json template you are using. Is the web root defined in composer.json? What version of Drush?
leymannx avatar
ne flag
But in the end I think it's always safer to execute Drush commands from within the webroot.
liquidcms avatar
us flag
@Clive, yes, that's the answer. I can run in project root but Drush still thinks of things as from docroot. Excellent. Thank you.
liquidcms avatar
us flag
Not sure how to mark a comment as the answer :(
leymannx avatar
ne flag
@liquidcms – You can add and accept that as answer yourself then to help future readers find the solution quickly.
Score:0
us flag

If you use a drush alias, it shouldn’t matter where you run the command from e.g

drush @site some-command

The webroot is specified in the alias.

More info https://www.drush.org/latest/site-aliases/

liquidcms avatar
us flag
That's an alias to the site url. It won't have any impact on Drush not handling path to file arguments correctly.
us flag
@liquidcms The drush alias contains various settings including the webroot directory specified in the root setting eg “root: /other/path/to/live/drupal”
Score:0
us flag

Clive didn't post as an answer so I will just copy here:

Drush commands run as if from the web root (not execution path) as the working directory. So even though running command from the project root; argument paths have to be entered as if coming from the web root.

vendor/bin/drush locale-import fr ../translations/translations.fr.po

  • from the project root

David's answer would also work if you were using aliases (which I am not).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.