Get a crashed Drush working again in Mac OSX | Must-have Drupal toolkit

May 13, 2016

Joris Snoek - Business Dev
+31 (0)20 - 261 14 99

Drush, the must-have toolkit for every Drupal developer. Installing Drush is not a problem when working via Composer. However, as with most of the applications that are dependent on other applications it can go wrong. Especially after upgrading your system or upgrading your MAMP / AMPPS / XAMPP / ... stack.

Drush depends on a number of smaller applications: PHP, MYSQL and of course Drush itself. As soon as it goes wrong, most of the developers (at least I hope) are searching through Google for a solution to the problem.

Common messages include:

  • "No Drupal site found, only 'Drush' cache was cleared."
  • "Drush was not able to start (bootstrap) the Drupal database."

These messages can even occur when working from the root of the Drupal environment.

  1. Why is this happening?
  2. And which solution is the right one?

1. Why is this happening?

The user can receive both messages when data in settings.php is not yet properly filled in.
This is also the most common message that you may receive with Drush when it goes wrong out of the box. The reason is that the wrong PHP or MySQL is called. (Usually MySQL).

You can find some solutions when entering the error messages in Google:

  • Changing the word localhost in the settings.php to
  • Creating a symbolic link from the path to your mysql.sock to /var/mysql/mysql.sock
  • Some are even giving the advice to use Drush 6.0.

Almost all the tips that are given are dependent on the situation and don’t work for everyone. The most important thing for Drush is that the right MySQL and PHP are configured:

Configure the correct MySQL and PHP version

On OSX the PHP is by default called from the following path: /usr/bin/php
This can be checked quite quickly by typing which php on a command line:

Usually this is not the PHP from the stack that you use for your Drupal install.

You can quickly check this by comparing the version number with the PHP version that you are using for Drupal. The chance that the PHP version of your OS is equal to your stack is quite small. Type php -v in the terminal and PHP will give you the version number.

2. Which solution is right?

You can use a bash_profile to make sure that every instance of the terminal is using the same versions of PHP and MySQL. This is a hidden file in the /~ path or the home directory. Here we specify which PHP / MySQL and Drush we will give to the bash profile.

Looking up the paths to use.

The paths used are dependent on the stack you are using. As an example I am using AMPPS. XAMPP and MAMP are using similar paths.


First of all it is useful to discover the Drush path. If you have used the instructions from, then this will be "/usr/local/bin/drush". To be sure you can type which drush in the terminal.

If this does not result in a path, then I advise you to check the instructions from


After we have found Drush it is time for PHP. Most apache stacks contain more than one PHP version. Once you change your PHP version, some stacks automatically change a symbolic link to the folder with the active version.

Because this is not happening with every stack, I am using a variable for the folder name of PHP.

Here you will put the name of the folder containing the PHP version which you are using for the Drupal install. To check if this is the case, you can type ls -la in the terminal within the application folder of your stack. (As shown in the screenshot).

The directory of PHP within AMPPS is /Applications/AMPPS/"PHPVERSION"/bin in my case "php-5.6" which changes the full path to: "/Applications/AMPPS/php-5.6/bin".


Finally we need the MySQL. Also this is dependent on the stack being used.
For AMPPS this is "/Applications/AMPPS/mysql/bin". (See previous screenshot)

Creating the bash profile

We will add the three paths found in the previous step to the bash profile of OSX.

The bash profile is a file that can add applications to the path variable of OSX.

We will use a text editor to modify the .bash_profile in the home directory.

The home directory is easily accessible by typing cd ~ in the terminal. Depending on the settings of the terminal it can also be sufficient to open a new screen.

By default, the home directory is open when you open a new instance of the terminal.

From the home directory we will edit/create the .bash_profile with a random text editor.
I am using Nano, other people will use Vim or TextEdit. For Nano you only need to enter 'nano', followed by the file name (in the terminal): nano .bash_profile.

In this file, we will add our paths to the $PATH variable. As example for simply changing PHP versions I have added the name of this folder as a separate variable.

To do this, enter the following:

export PHP_ID="php-5.6"

Where “php-5.6” is the name of the folder. Then you can use PHP_ID in the remainder of the profile.

Next we will add all paths to the Path variable:

export PATH="/Applications/AMPPS/$PHP_ID/bin:/Applications/AMPPS/mysql/bin:/usr/local/bin/drush:$PATH"

If everything went well, you have now added/created two lines to the profile.

To write to the profile, you will use CTRL + O followed by CTRL + X to close nano.

You will now get a warning if you want to write, press enter to confirm.
When you receive a permission denied then it is possible that you need sudo rights to write to/create this file.

Enter sudo su - followed by the admin password and execute the steps again.
Once the lines have been added and saved, all the open terminals need to be closed (or refresh source .bash_profile in.)

If everything went well, you can now use Drush again, congratulations :)

Credits header foto


Stay up-to-date

Subscribe to our Lucius newsletter
and be the first to know about new articles!

Need even
more knowlegde?