Fixing Drush when it says a "higher level bootstrap" is required, even though you're inside a Drupal website's working directory

Date: Wed Jan 07 2015 Drupal Tutorial
I'm trying to get ready for a Drupal 8 port, and one of the steps is to get Drush set up. Nowadays that means setting up Composer and running some magic commands with Composer that supposedly sets up Drush. The problem then came when I cd'd into the root of my Drupal 6 site, and tried to run "drush pm-list --core" to generate a list of installed modules to prepare a readiness spreadsheet. The error message that came up gave me a big WTF feeling:

$ drush pm-list
Command pm-list needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command.                                                                                                                                                  [error]
The drush command 'pm-list' could not be executed.                                                                                                                                                                                                                                                    [error]
Drush was not able to start (bootstrap) the Drupal database.                                                                                                                                                                                                                                          [error]
Hint: This may occur when Drush is trying to:
 * bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See `drush topic docs-aliases` for details.
 * connect the database through a socket. The socket file may be wrong or the php-cli may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for details.

The problem with this is that my current working directory was the root of a working Drupal website. Typing "drush sql-connect" sure enough gave me the correct MySQL command to connect with the database. So why the bleep was Drush failing like this.

After quite a bit of yahoogling and pondering I eventually read the Drush documentation carefully. On the configuration page there are various things said about the PHP version and configuration required to successfully run Drush. A dawning of realization grew upon me that said "your PHP is too old".

The site in question is hosted on Dreamhost. Running "php --version" told me that Drush was likely being executed by PHP 5.3. On that configuration page is special instructions for PHP 5.3. Hurm.

It also says you can do this:


$ export DRUSH_PHP='/path/to/php'

On Dreamhost VPS's other PHP versions are in /usr/local/bin with this sort of setup:


$ which php-5.4
/usr/local/bin/php-5.4

Hence ...


$ export DRUSH_PHP='/usr/local/bin/php-5.4'

And Drush magically starts working:


$ drush pm-list --core
 Package          Name                               Type    Status         Version 
 Core - optional  Aggregator (aggregator)            Module  Not installed  6.34    
 Core - optional  Blog (blog)                        Module  Enabled        6.34    
 Core - optional  Blog API (blogapi)                 Module  Enabled        6.34    
 Core - optional  Book (book)                        Module  Enabled        6.34    
 Core - optional  Color (color)                      Module  Enabled        6.34    
 Core - optional  Comment (comment)                  Module  Enabled        6.34    
...

That configuration page has other useful information for configuring Drush execution. Just remember to add everything to your ~/.bashrc so it's active the next time you log in.