Drush installed and running; No Drupal site found even with uri specified After much trial and tribulation, I thought I had drush all ready to roar. Much excitement. But then, no joy...

Drush is working. The sites operate fine via MAMP. Regardless, a "drush cc all" command returns: 

No Drupal site found, only 'drush' cache was cleared.                                          [warning]
'all' cache was cleared.                                                                       [success]


This question has stumped drupalcon attendees and very experienced developers. Any ideas?

I am on Mac OS 10.9.3
using MAMP (free) Version 3.0.5

Here is my drush status:

 Drupal version         :  7.29-dev                               
 Site URI               :  http://default                         
 Database driver        :  mysql                                  
 Database hostname      :  localhost                              
 Database username      :  db_user                           
 Database name          :  db_name                      
 PHP executable         :  /usr/bin/php                           
 PHP configuration      :                                         
 PHP OS                 :  Darwin                                 
 Drush version          :  7.0-dev                                
 Drush temp directory   :  /tmp                                   
 Drush configuration    :                                         
 Drush alias files      :                                         
 Drupal root            :  /Applications/MAMP/htdocs/mysite.dev 
 Site path              :  sites/default    


Have tried executing drush from /Applications/MAMP/htdocs/mysite.dev; from /Applications/MAMP/htdocs/mysite.dev/sites/default; and using drush cc all --uri=http://localhost/mysite.dev

Tried running drush from sites/default. Same result.
Please double check that all below points are addressed.


You're running drush in Drupal root folder or folder containing settings.php file.
The mysql command exists (and it's in your PATH).

Please note that the database command depends on your database driver set in your settings file (e.g. sqlcmd for SQL Server; for details check different classes in Drush's /src/Sql).

If the command is missing when running in any folder, make sure path to its binary file is added into your PATH system variable.
Your PHP has PDO extension enabled (check by: php -m | grep pdo or drush sqlc).
Your PHP has database extension enabled (e.g. mysqli) (check by: php -m | grep mysql).


To investigate what's exactly wrong, run drush with -v (verbose) and -d (debug) flags, e.g.

drush -vd status
drush -vd ev "echo 123"
drush -vd cc all


and check for any errors.




  mysql extension for PHP PDO is not installed. Check your php.ini to see how you can enable it.


Install database extension (e.g. mysqli) (as per above 4th point).

For MAMP, see: Drush does not work on my Mac



MAMP

Since you're using MAMP, make also sure you running the right version of php binary (check by which php) and it should point to /Applications/MAMP/bin/php/php5.X.X/bin/php. If not, please add the path into your PATH in your rc files (e.g. ~/.bashrc):

# For MAMP (OSX)
PHP_VER="5.6.10" # Or: 5.4.19/5.5.3 (check by: $ ls /Applications/MAMP/bin/php/php*)
export PATH="$PATH:/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php$PHP_VER/bin:/Developer/usr/bin"




XAMPP

For XAMPP for Windows, similar thing, add your C:\xampp\mysql\bin into your environment variable PATH. 

Debugging

If your drush command fails for some reason, here are the suggested steps to debug drush (shell commands).


Install and enable PHP xdebug extension. Verify by php71 -i | grep xdebug. 
Verify Drupal root, Settings File and Database are present in drush status.
Generate trace file:

drush ev "xdebug_start_trace(); drush_drupal_cache_clear_all(); echo xdebug_get_tracefile_name(); xdebug_stop_trace();"


or:

drush ev "xdebug_start_trace(); print_r(_core_site_status_table()); echo xdebug_get_tracefile_name(); xdebug_stop_trace();"


If xdebug is enabled for different PHP version, specify with DRUSH_PHP=/path/to/php.

If successful, trace output file should be printed at the end, so take a note of it.
Now open and check the trace file.
To test or compare drush output with clean Drupal, you can install new Drupal in empty folder by:

drush -y qd --no-server --core=drupal-8
cd quick-drupal-*/drupal*
drush status