I am successfully using Drush on two sites on my dev server, yet on the exact same machine it does not work correctly with a third site. All are hosted locally, using MAMP Pro to manage the OS X Apache and MySQL servers and to provide local name resolution.

An attempt to run drush updatedb --verbose=2 on the site that will not work produces:

$ drush updatedb --verbose=2
Initialized Drupal 6.13 root directory at                               [notice]
/Development/central.org.nz/central.org.nz
Initialized Drupal site central.org.nz at sites/default                 [notice]
Drush command could not be completed.                                [error]

I notice that the output from drush status is different in one way between the sites that work and the one site that does not—the site URI is listed as "http://default on the two sites that work, while it is listed as the correct site URI on the one site that does not work. That seems odd—particularly as I have not set a site URI in the settings.php file for any of them.

All are running with 128M of RAM allocated to command line PHP via the settings.php file.

Full drush status output for the site that does not work is:

  PHP configuration : /Applications/MAMP/conf/php5/php.ini
  Drupal Root       : /Development/catalyst.ac.nz/catalyst.ac.nz <em>[this is the correct path]</em>
  Drupal version    : 6.13
  Site Path         : sites/default
  Site URI          : http://default
  Database Driver   : mysql
  Database Hostname : 127.0.0.1
  Database Username : catalyst
  Database Name     : <em>[correct database name]</em>
  Database Password : <em>[correct pass]</em>
  Database          : Connected
  Drupal Bootstrap  : Successful
  Drupal User       : Anonymous

Nothing else seems to be different between the two. Any leads?

CommentFileSizeAuthor
#15 538702.patch1.39 KBowen barton

Comments

babbage’s picture

Darn it, that full drush status output above is for one of the sites that does work. Here is the status for the one that does not:

  PHP configuration : /Applications/MAMP/conf/php5/php.ini
  Drupal Root       : /Development/central.org.nz/central.org.nz
  Drupal version    : 6.13
  Site Path         : sites/default
  Site URI          : http://central.org.nz
  Database Driver   : mysql
  Database Hostname : 127.0.0.1
  Database Username : [correct database username]
  Database Name     : [correct database name]
  Database Password : [correct pass]
  Database          : Connected
  Drupal Bootstrap  : Successful
  Drupal User       : Anonymous

Should always preview my posts!

babbage’s picture

Version: All-Versions-2.0 »

Updated to All-Versions-HEAD; still seeing same problem.

mattyoung’s picture

I have the same problem. I'm using MAMP and two devel sites on the same multi-site install, drush works on one site but not the other, just give 'Drush command could not be completed'. Adding the -d switch and get:

Found command: status [0.018 sec]                                    [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.019 sec]   [bootstrap]
Initialized Drupal 6.13 root directory at                               [notice]
/Users/matthewyoung/devel/drupal/drupal-6/drupal-6 [0.026 sec]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.027 sec]   [bootstrap]
Drush command could not be completed. [0.206 sec]                    [error]

The site that works has lots of modules enable, the site that doesn't work is a fresh install. Both have identical settings.php except the $db_url.

jonhattan’s picture

Are you running drush from the site path or passing --root and --uri in the command line.

@dbabbage: 'it works' mean that the updatedb command is run succesfully by performing the updates?
If you doesn't have provied a --uri and you're running drush from /var/www/drupal/sites/example.com, drush will extract the information from the path and will set:

Site Path         : sites/example.com
Site URI          : http://example.com

it's annoying that your output is contradictory with that.... as sites/default is only used as a fallback if no --uri or path can help drush determine which is the site.... Do you have a valid site un sites/default? do you are using --uri in the drush invokation? It seems to me that the two sites that works really doesn't work (both of them has `Site Path: sites/default` isn't it?) and the one that you think doesn't work does really work but the command fails for some reason. Does it make sense? Can you perform some `drush status` withing several directories and alternatively by using --uri in order to get close to the problem?

mattyoung’s picture

$ drush -l http://site-A.com status
Drush command could not be completed.                                [error]
$ drush -l http://site-B.com status
  PHP configuration : /Applications/MAMP/conf/php5/php.ini
  Drupal Root       : /Users/matthewyoung/devel/drupal/drupal-6/drupal-6
  Drupal version    : 6.13
  Site Path         : sites/site-B.com
  Site URI          : http://site-B.com
  Database Driver   : mysqli
  Database Hostname : localhost
  Database Username : xxxxx
  Database Name     : xxxxx
  Database Password : xxxxx
  Database          : Connected
  Drupal Bootstrap  : Successful
  Drupal User       : Anonymous

How to debug this to find out what cause the error?

jonhattan’s picture

drush --debug -l http://site-A.com status

mattyoung’s picture

$ drush --debug -l http://site-A.com status
Found command: status [0.02 sec]                                     [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.021 sec]   [bootstrap]
Initialized Drupal 6.13 root directory at                               [notice]
/Users/matthewyoung/devel/drupal/drupal-6/drupal-6 [0.028 sec]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.029 sec]   [bootstrap]
Drush command could not be completed. [0.211 sec]                    [error]

I did this before but it doesn't show any useful information at all :(

Is there anyway to know what the error is? Is there some module I need to enable? The site that doesn't work is a fresh install of Drupal and no contents. The one that works has lots of modules enables.

babbage’s picture

@jonhattan: I am running drush only from the root of the installation, and without specifying either --uri or --root. Each installation on the development server is an entirely separate Drupal install, being hosted on a separate locally-resolved URL. In each install, the site is installed in sites/default, and without the site base url being specified in the settings.php.

Is installing the site in sites/default not the norm for single-site installations?

babbage’s picture

Also yes, "it works" means the db update ran successfully.

jonhattan’s picture

Status: Active » Postponed (maintainer needs more info)

@dbabbage: there's no problem with using sites/default of course

It's a weird thing and it seems we can't get more clues from drush itself. If tracing the code is an option for you, go on :)

babbage’s picture

This is driving me insane. I've tried quite a few things to try and identify where this is coming from. It is something in the database, as a clean install with all of the same modules etc doesn't have the problem until I install a SQL dump from the live site... YET on the live site Drush works just fine. So it is something that is installation-specific that doesn't break Drupal itself if it is wrong, but does break Drush??

babbage’s picture

Title: Works on two sites, not on third on development server » Drush works on server and on dev server, but not with a database migrated from one to the other...
Status: Postponed (maintainer needs more info) » Active

Updating title to current information...

babbage’s picture

Title: Drush works on server and on dev server, but not with a database migrated from one to the other... » Drush fails if parent of Drupal root directory contains a backup of the settings.php file

Title says it all. Finally figured out through an extensive process of testing and elimination that it was something that was specific to the particular directory I had this site installed in that was the problem... and putting an entirely fresh install in the same location had the same problem.

I then thought it was some odd residue somewhere in an Apache config file that I'd set up wrongly... but nope, it was the presence of a settings.php file in the parent of the Drupal root install. Put one there and the Site URI changes from http://default to http://example.com, and Drush fails.

I have not looked into why, but I'm going to presume that what is happening is that Drush looks in the parent of the root of that install to see if there is a settings.php there, and if it finds one it assumes that means it is in a multi-site installation. However, the adjustments that it then makes to how it operates are incorrect as it was not in fact operating in a multisite install. If this deduction is correct, it suggests Drush needs a more robust way of identifying whether it really is in a multisite scenario.

And that's where I leave this issue. This has sucked a *lot* of my time working out why this was breaking. It definitely should be fixed, but I'm not up for it (and might not be capable of fixing it anyway). All the best to whoever is willing to take this on. :)

moshe weitzman’s picture

Assigned: Unassigned » owen barton
Category: support » bug
owen barton’s picture

StatusFileSize
new1.39 KB

This is a pretty subtle issue indeed - originally I was going to post that I couldn't reproduce this, but then I noticed that it could potentially cause issues if the URI is not provided, and Drush is called from a directory other than the one you want to bootstrap. Ordinarily (i.e. if the cwd does not contain a settings.php) then Drush will try it's "last resort" which is to pass Drupal a URI of "http://default" (since we have no other clues, and this actually works fine for a bunch of common cases) and see what happens. Obviously if the default site is not configured nothing good will happen, but if it is configured you will get the default site and be able to work with it.

However, if there is a settings.php in the current directory, it will pass Drupal a URI of http://[current directory name]. It is not clear how this is causing the problems described. Unless the current directory happens to be named after a sites directory (that you don't want) Drupal should pick the default site and proceed as above. The URI passed in won't be http://default, but neither http://default nor http://[current directory name] are likely to be the "correct" URIs so it shouldn't really matter.

@dbabbage where is the http://example.com coming from in your case? Is the directory above your drupal root (with the settings.php causing the problem?) named "example.com" and you have a "sites/example.com" directory with an unconfigured settings.php that is breaking Drush? If not, then there seems to be something else going on, and we will need quite a bit more detail about your directory structure, any settings.php or drushrc.php and how you are calling drush to be able to figure this out.

The attached patch checks that the current directory is within a directory named "sites" before suggesting it as a site path. If folks with issues could please test the attached patch and post results back here that would be great. I am not sure that this patch is committable, because some people use symlinks to sites, and run drush from a site directory where the parent is not named "sites" (setting the Drupal root via a drushrc) and using the auto URI pickup in this scenario. There are probably other approaches we could consider though (e.g. stop descending if you hit a directory with index.php in it).

owen barton’s picture

Status: Active » Needs review
babbage’s picture

I haven't tested the patch yet, but to answer your specific questions:
a) The site is installed in /sites/default.
b) The settings.php file in /sites/default is configured for the site in question, but does not specify what the URI is.
c) I always run Drush commands from the Drupal root directory for that install, i.e. to avoid any possible confusion, in the directory that contains the index.php file.
d) As it happens, the directory in which that resides is called example.com (obviously not actually example.com, but it is named with the domain). Your statement that lacking all other information, Drush takes the name of the parent directory as the URI explains how the Drush status was listing the URI as http://example.com... I was having trouble figuring out how it was that Drush was picking up the URI in this one case when it doesn't on any other site where I have the site installed in /sites/defult. I'm a bit surprised at this behaviour as on all the live sites I use, the parent of this directory would be public_html not example.com anyway so I'm not sure this would be particularly useful... but perhaps on some hosts it provides some useful information I guess.
e) I do not have any other sites configured in /sites... specifically there is no sites/example.com so that is not why Drush was breaking.

The only thing I had to do to fix Drush for this install was remove the copy of the settings.php file that was sitting *alongside* the folder example.com.

Here is one further possible lead: the parent of example.com was *also* called example.com. This arose because I have a directory Development, inside which I have a directory for each site (example.com) and inside that I have one directory which is the development install for the site (example.com) as well as other files that relate to that site. I guess possibly the combination of /Development/example.com/example.com/[Drupal-install-here] plus the stray backup file in /Development/example.com/settings.php could have confused the heck out of Drush?

babbage’s picture

@Owen Barton: I think your suggestion to stop ascending if you hit a directory with an index.php would have solved my issue... it would have reverted back to http://default, which is what I was expecting to see, and it would have the correct working directory in my case. Now that I've thought about what you said I'll bet it was the grandparent of the Drupal directory that it had latched onto as the working directory, because of the location of the settings.php... and that's easy to test...

babbage’s picture

Sure enough, if I change the path to:
/Development/example.net/example.com/[Drupal install here]
and have a duplicate of my settings.php at
/Development/example.net/settings.php

...then Drush reports the URI as http://example.net instead of http://example.com.

So Drush was identifying the grandparent of my Drupal install as being the root directory of the installation, because of the presence inside it of a settings.php.

There doesn't appear to be any limit to how far Drush will ascend. Putting a settings.php in /Development/settings.php results in Drush reporting the URI as http://Development

However, it does accept the first settings.php that it finds... if multiple extraneous settings.php files are put in the hierarchy it stops at the first parent where it finds one. Therefore, if I run Drush from within sites/default it works correctly even with extraneous settings.php files in the hierarchy above.

So I guess the question I'm left with is, if Drush is being called from the root folder of a Drupal installation and there is a directory called /sites in the current folder, why does it *ascend* instead of *descending* to look for a settings.php file?

owen barton’s picture

e) I do not have any other sites configured in /sites... specifically there is no sites/example.com so that is not why Drush was breaking.

In this case my hypothesis is not correct - there must be something else going on here. If the above is the case it shouldn't matter what URI we pass into Drupal - it should always use sites/default, and use that settings.php. While we could try and improve the heuristics around URI detection I don't think that will fix the root cause of this issue.

Some other points of potential confusion:

* We decend directories to find a settings.php if no specific URI is passed in because this allows drush to bootstrap the correct site with no configuration as long as you are inside the Drupal root an anywhere inside the sites directory. As an example if I call Drush from /var/www/mydrupalroot.com/sites/mydrupalroot.com/modules/custommodule/ it will (a) decend to /var/www/mydrupalroot.com/sites/mydrupalroot.com/ find settings.php and set the URI to mydrupalroot.com. It will then(b), if no specific Drupal root directory was passed, descend to /var/www/mydrupalroot.com/, find index.php and name this directory as the Drupal root. We can't really ascend directories because we would have no idea what directory to pick at each point.

* There is no limit to how far Drush would ascend because adding a limit would not achieve anything. Let's say you have both sites/default and sites/example.org as valid sites, and you want to download a module to example.org. You start Drush from the Drupal root, but don't pass in a "-l" parameter. If Drush decends to "/" without finding a settings.php it will pass http://default, which is an incorrect fictional URI, but ensures that there is an arbitrary string in this variable (since many places in Drupal assume it is present) and Drupal will select sites/default in any case. If however there is a settings.php in /Development, then Drush will pass http://Development, which is equally arbitrary and fictional, but should result in the exact same result of sites/default. The possible exception is if you have a settings.php in a directory named example.org (even if this is "above" the Drupal root, Drush/Drupal would pick that site, since it is a valid site, however that is arguably the correct behavior and is one that I have used from time to time.

* Your message suggested that you thought the settings.php we located in (a) is actually used - however this is not the case. We simply pass the name of this directory in to Drupal as a URI "hint". If Drupal's conf_path() mechanism finds a directory in sites.php that matches the URI with the appropriate rules it will use the settings.php from that directory (this would normally be the same settings.php we found). However if the directory does not exist for whatever reason it should always fall back to sites/default if it exists, and use that settings.php.

babbage’s picture

Part of my confusion here was between the use of "descend" and "ascend". In my head moving from /var/www/mydrupalroot.com/sites/mydrupalroot.com/modules/custommodule/ to /var/www/mydrupalroot.com/sites/mydrupalroot.com/ was "ascending" (moving up a hierarchy) but it is clear now from your example that this is "descending"... therefore these words in much of what I was saying needs to be reversed to be understood with my original intention...

moshe weitzman’s picture

Status: Needs review » Postponed (maintainer needs more info)
DrMiaow’s picture

I was stung *BADLY* by this as well. I backed up my settings.php in the root and then spent two days trying to work out why some servers worked and others didn't.

The fact that the bug still exists and this thread has been paused *three years* over a disagreement of semantics is a farce.

owen barton’s picture

@DrMiaow - this issue was not paused due to a disagreement in semantics, it was because nobody who experienced the issue actually tested my patch in #15 and indicated if it fixed the issue for them or not. Perhaps you would be willing to do that?

greg.1.anderson’s picture

The code in the patch looks good to me, but I can't reproduce this problem on D6 or D7. When I copy my settings.php file to the Drupal root, everything keeps working just fine. If I have sites/default/settings.php, it is found; if I have sites/mysite/settings.php, it is found if I include --uri=mysite, and it is not found without it, regardless of whether I have a copy of settings.php at the root or not. Looks like we still need confirmation that the patch is helpful.

owen barton’s picture

Yes - I couldn't reproduce the problem as described, but I am also not very clear on the exact steps to reproduce.

The only issue I could find (which is what the patch fixes) was one with multisite where if you have a settings.php in your Drupal root (or similar) AND the name of your Drupal root directory matches one of your site directories, it could trigger a specific multisite, rather than sites/default, which you might not otherwise expect.

greg.1.anderson’s picture

Version: » 8.x-6.x-dev
Status: Postponed (maintainer needs more info) » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If desired, you may copy this bug to our Github project and then post a link here to the new issue. Please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.

greg.1.anderson’s picture

Status: Closed (won't fix) » Closed (duplicate)

Opened a PR with a slightly different implementation on github. https://github.com/drush-ops/drush/pull/159