5

I've tried other solutions, but none of them are specific to my setup. I just started using the new Linux subsystem featured in the recent Windows 10 update. I'm using WAMP x64 v3.0.6, and have successfully cloned my website and got it up and running. At the root of the Linux subsystem, I installed Drush globally with Composer, using the directions given on the Drupal webapage.

Typing drush status returns the following when I run it in my default directory:

Drupal version         :  7.50
 Site URI               :  http://default
 Database driver        :  mysql
 Database hostname      :  localhost
 Database port          :
 Database username      :  root
 Database name          :  aerosphere
 PHP executable         :  /usr/bin/php
 PHP configuration      :  /etc/php5/cli/php.ini
 PHP OS                 :  Linux
 Drush script           :  /home/bob/.composer/vendor/drush/drush/drush.php
 Drush version          :  7.1.0
 Drush temp directory   :  /tmp
 Drush configuration    :
 Drush alias files      :
 Drupal root            :  /mnt/c/wamp64/www/drupal-7.50
 Site path              :  sites/default

But, as mentioned in the title, drush cc all returns No Drupal site found, only 'drush' cache was cleared.[warning] I assume it has something to do with adding a path to the .bashrc, but I don't know what to add. Any tips would be greatly appreciated!

My question is different from "Drush - No Drupal Site Found when clearing cache", they're on a Mac and using MAMP, and I'm using WAMP on Windows. I've tried the solutions offered on that post, but the issue has not been resolved.

I'm obviously having issues connecting to MySQL as I get this when I run mysql command:

The program 'mysql' can be found in the following packages: * mysql-client-core-5.5 * mariadb-client-core-5.5 * mysql-client-core-5.6 * percona-xtradb-cluster-client-5.5

Try: sudo apt-get install .

So I've added these lines to my .bashrc file:

PATH="$HOME/.composer/vendor/bin:$PATH"
export PATH="/mnt/c/wamp64/mysql/mysql5.7.14/bin:$PATH"

The top line was added to get drush working. I've checked multiple times, and I have the path correctly set, but it's still not working.

  • Are you running drush from the /sites/default directory from within Drupal? – lukedekker Jan 29 '17 at 17:47
  • @Pierre.Vriens I've already explained that my question is different. They're on a Mac and using MAMP. I've tried the solutions offered on that post, but the issue has not been resolved. – Kellen Jan 30 '17 at 15:37
  • @lukedekker Yes, I am. – Kellen Jan 30 '17 at 15:38
  • @Pierre.Vriens Sorry, I tried to explain that other solutions hadn't worked in the first paragraph. I should've been more specific and referenced that post. Thanks for reopening. – Kellen Jan 30 '17 at 16:17
  • 1
    no need for sorry, good to know that we now have a more accurate question. Fingers crossed that it won't get marked as a duplicate of some other question (I can't believe there is no other similar/duplicate question). Good luck! – Pierre.Vriens Jan 30 '17 at 16:29
10
+25

There are a few things you can do to help debug your drush. Here is what you can try:

Debug output

Use drush cc all -vvv

This will provide you with some valuable information in terms of what Drush is doing in the background and maybe show you the actual error message.

Check your settings.php

Depending on your setup you may be passing in environment variables to your settings.php file for a database configuration for instance. Or perhaps to provide memcache. Drush unfortunately does not pick these up as it's bypassing apache. Therefore I would give it a test run without environment variables to see if that eliminates the issue or help narrow it down. For debug purposes it may be worth just using a clean copy from the example.settings.php and just modifying the database array to test this.

Check the mysql client is available

This is one that tripped me up a while ago and the drush -vvv will point you in the right direction. If it can read the settings.php, which it appears it seems to be able to as it gets the db settings, then perhaps it can't connect to your mysql database. One of the issues I had was that mysql client command was not available. E.g. try calling 'mysql' and see if that works. After fixing that it worked. In my Mamp setup it was just a matter of ensuring the correct path to the executable was in my shell $PATH.

I hope this helps.

  • 2
    Thanks for the help. I'm obviously having issues connecting to mysql. I get this when I run mysql: mysql The program 'mysql' can be found in the following packages: * mysql-client-core-5.5 * mariadb-client-core-5.5 * mysql-client-core-5.6 * percona-xtradb-cluster-client-5.5 Try: sudo apt-get install <selected package>. I've added these lines to my .bashrc file: PATH="$HOME/.composer/vendor/bin:$PATH" export PATH="/mnt/c/wamp64/mysql/mysql5.7.14/bin:$PATH". The top line was added to get drush working. Is the bottom line wrong? – Kellen Feb 8 '17 at 1:14
  • Sorry, I don't have a WAMP setup so I may not be the best person to ask as it's specific to that setup. First thing I would check is if the folder "/mnt/c/wamp64/mysql/mysql5.7.14/bin" exists and "mysql" is present. For instance, it could be that your mysql was updated so that path is not valid anymore so just a matter of adding the right one to your .bashrc file. – JNP Web Developer Feb 8 '17 at 20:45
  • Okay, thanks. Does the syntax look correct? I don't know much about the syntax in the .bashrc file. – Kellen Feb 8 '17 at 20:50
  • Hi there again. Sorry to bother you, but I'm still working on this. I've checked multiple times, and I have the path correctly set. It's still not working. Can you export two paths in the bashrc? Because I had to export the path to drush. I wonder if that's conflicting with the export for the mysql path. – Kellen Mar 10 '17 at 2:56
  • @KellenLester, it's a bit difficult to help without knowing the context. Perhaps combine it all into one line and make sure MySQL is included first: PATH="$HOME:/mnt/c/wamp64/mysql/mysql5.7.14/bin:/.composer/vendor/bin:$PATH" All you're doing is saying, please check these locations for all the binaries I want to make executable in the shell. Another tip would be to use the which command to make sure you are pulling in the right ones. e.g. which mysql and which drush. If everything is right it should give you the locations above. Hope this helps. – JNP Web Developer Mar 12 '17 at 15:33
5

This usually happens when the directory where you are calling drush is not a Drupal site or not a sub-directory of a Drupal site or maybe drush cannot recognize your site. Here are some tips which might help:

  • If you are working on a single-site Drupal installation, make sure sites/default/settings.php exists.
  • If you are working on a multiple-site Drupal installation, make sure:
    • You have a settings file for your site in sites/example.com/settings.php, where example.com would be usually your site's domain.
    • You run the command drush use example.com to change to the site you are currently wanting to work with.

Hope it helps. Happy coding!

4

Noting that your drush status output does give a valid root, site path, database user, and database name, that means that drush is finding a valid settings.php file with credentials in it and can read it.

However, drush status does not have the line

Drupal bootstrap                :  Successful

which would indicate that it can actually load.

If you run

drush sql-cli

It will attempt to generate a mysql client connection to the database and that will probably generate a more readable error to what is happening.

Also, drush sql-connect will show the connection information (including passwords, so be careful pasting).

  • Okay, I tried running drush sql-cli and I got sh: 1: mysql: not found. I guess it has something to do with the path? Here's what I've got in my .bashrc file. export PATH="$HOME/.composer/vendor/bin:$PATH" export PATH="/mnt/c/wamp64/mysql/mysql5.7.14/bin:$PATH". I had to add the top line to get drush working. I tried to add the bottom line to fix this issue initially, but it didn't work. Am I doing something wrong? – Kellen Feb 8 '17 at 1:08
  • Sorry to bother you again, but I'm basically desperate. Could you share any light on what I found? – Kellen Mar 10 '17 at 2:58
3

Drupal site not found error comes up when Drush cannot find your Drupal installation. You can specify the path to the Drupal installation as shown below:

drush -r path/to/docroot cc all
1

Had the same problem when running drupal on windows and using drush on the Windows Subsystem for Linux. jnpWebDeveloper's answer helped me to fix it. These are the steps i needed to do:

  1. mysql is missing on the subsystem. You need to install it via sudo apt-get install. Pointing in the path to your windows mysql executable will probably not work even if the path is correct.
  2. You will need to replace localhost with 127.0.0.1 as the hostname in your settings.php. Otherwise mysql will try to connect to a mysql server on your linux subsystem using the local socket. You want it to be able to connect to the mysql server running on windows.
1

One specific case where this might happen, with the exact same core status report, is when ~/.my.cnf is setup with only a password entry, without a matching user, and the database connection in settings.php is setup with a different user (and password). The mysql error log will probably say something like this for each drush run:

2018-06-29T08:49:30.926226Z 1046 [Note] Access denied for user 'user'@'localhost' (using password: YES)

I.e. database connection fails during drush/drupal bootstrapping. In my case this happens in Drush 8.x. I haven't investigated other versions. It seems like drush uses your ~/.my.cnf instead of values provided by settings.php

Solution

Either add an additional user entry in ~/.my.cnf or remove the password entry:

[client]
user = your_mysql_username
password = your_mysql_pass
0

Not able to execute mysql command (or other equivalent command depending on your db driver) from the shell is the main problem of Drush not being able to connect to Drupal site. Run drush -d sql-connect to find out that is the case.

The following lines added to ~/.bashrc should be fine:

export PATH="$HOME/.composer/vendor/bin:$PATH"
export PATH="/mnt/c/wamp64/mysql/mysql5.7.14/bin:$PATH"

where /mnt/c/wamp64/mysql/mysql5.7.14/bin is your path to your mysql command.

To reload the shell startup script, run:

~/.bashrc

or re-login. This can be also verified by echoing your PATH by: echo $PATH in Bash shell.

For any other similar issues, check: Drush installed and running; No Drupal site found even with uri specified.

0

This is most likely an edge case but I'll share it in case it helps someone.

In my case, this issue was triggered by changing the password for root in MySQL (server is Linux).

I have a file, ~/.my.cnf, which contains these lines:

[client]
user=root
password=mypassword

This allows me to run mysql commands inside bash scripts without requiring user interaction. Seems it affects how Drush works too. I changed the root password without updating this file, and the drush problem began. Updating the password fixed the problem, as did removing this file.

0

Wow! For me it was the inclusion of the settings.local.php file which wasn't working anymore locally.

Previously I did it like so, and still do on the live server where it's still working. But locally on my macOS with MAMP this returned a wrong path and so the settings.local.php file wasn't included anymore and Drush didn't found the default site anymore.

// OLD WAY.
if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php')) {
  include DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php';
}

I fixed it by replacing the code by the one that's used in Drupal 8 and 9 and now is open for backporting, see https://www.drupal.org/project/drupal/issues/1118520.

// NEW WAY.
$local_settings = dirname(__FILE__) . '/settings.local.php';
if (file_exists($local_settings)) {
  include $local_settings;
}

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.