Score:0

How to specify setting.php file for drush?

in flag

I'm using Drupal 9 and Drush 11. I have two hosts, one for local testing (www.en9-local.pglatz.com) and a remote production server (www.electronovelty.com).

When I run drush status from either of these hosts, I see Site path is set to sites/default. How do I tell drush which settings.php to use? I tried using the uri argument on the command line; it does find the proper site path, but is also giving an error:

% drush status --uri=www.electronovelty.com
sh: 1: ^www.en9-local.pglatz.com$: not found
sh: 1: ^www.electronovelty.com$: not found
...

Ideally, it wouldn't involve editing files on the remote host, but set with a cmd line argument, env variable, or other setting outside the Drupal installation.

leymannx avatar
ne flag
I don't understand the question. Is this a multi-site? After you configured site aliases for Drush, you move into your local project dir and execute `drush cr` to clear your local site's cache and `drush @myalias cr` to clear your remote site's cache. If this is not a multi-site, settings.php always resides in sites/default dir. If this is a multi-site and you have another settings.php in sites/subsite dir for example, execute `drush cr -l subsite` to execute your local subsite's instance cache.
leymannx avatar
ne flag
Maybe you are confused that Drush is not installed globally anymore? Drush nowadays only supports one install method: As a local dependency of a Composer-based site. However, you can easily write your own Shell alias to achieve what you want, receiving some argument to then take that and `cd` into the right local directory before executing a Drush command there, and maybe a second argument for the corresponding remote alias. And I think Drush still takes the `--root` option to point to a certain dir on your local, doesn't it?
leymannx avatar
ne flag
That's `-l` then. `drush cr -l www.en9-local.pglatz.com` and `drush cr -l www.electronovelty.com`. (Although I'm not sure if this setup is a good idea in general.)
pglatz avatar
in flag
The problem I have is the site has a local and production version. I use the same codebase on both, and a settings file under sites for each, to point to the correct database (sites/www.en9-local.pglatz.com/settings.php, sites/www.electronovelty.com/settings.php). The sites run fine, but drush always uses sites/default/settings.php and I need a way to tell drush which settings file to use. Adding --uri to the drush command line results in the sh: errors above, as does using a site alias. I don't run drush on the remote site from my local, but do run it from the remote site itself.
leymannx avatar
ne flag
Telling you this the third time now ---> Use `-l`. Like `drush cr -l www.en9-local.pglatz.com`.
pglatz avatar
in flag
Thanks, I've tried it, and as I mentioned, I see an error before the command (successfully) executes: % drush cr -l www.en9-local.pglatz.com sh: ^www.en9-local.pglatz.com$: command not found [success] Cache rebuild complete.
Hodba Khalaf avatar
eg flag
the command that should work for you is "drush @www.en9-local.pglatz.com cr" you need to take the name of the directory under the site folder
pglatz avatar
in flag
@HodbaKhalaf thanks but when I enter `drush @www.en9-local.pglatz.com cr` I'm getting `Command "@www.en9-local.pglatz.com" is not defined.` -- isn't this a site alias notation? Do I need to make an entry in self.site.yml to make this work? I tried, but get the same error,
Hodba Khalaf avatar
eg flag
I think it might be something wrong with the drush installation. Try. to go inside the site folder "cd sites/www.en9-local.pglatz.com" and run the drush command from there. If it didn't work then try to reinstall drush using composer
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.