Installing Drush on MAMP

Drush logo

Drush provides command-line access to the Drupal installation. I'm not a big fan of the command-line but in the case of Drush I make an exeption. The time it takes to set up Drush is nothing compared to the time you gain during development. Examples? Drush pm-update (drush up) updates all core and contrib modules, including the database updates. With FTP-access this takes much longer.

Right from the start, during the development on a local machine (an AMP-stack, Apache, MySQL, PHP) Drush comes in handy.

I use MAMP on Mac OS X Yosemite.

Use the PHP version of MAMP

Before starting, we need to see what PHP version MAMP uses. To see that, open MAMP, click on Preferences and then PHP. In my case, PHP version 5.6.2 is used.

MAMP php versie

When we work with MAMP, we want to use the php version of MAMP, not the system version. Therefore, first check the PHP version in use by typing this command into Terminal:

which php

Normally you will receive the output /usr/bin/php. We want to use the version under /Applications/MAMP/bin/php/php5.6.2/bin/php. To change this, we have to edit the profile with root (sudo) access. Type:

sudo nano ~/.bash_profile

Now add the following line:

export PATH=/Applications/MAMP/bin/php/php5.6.2/bin:$PATH

Then click CTRL + X, then Y and Enter. In order to see the changes we have to reload the file with the profile we just changed:

source ~/.bash_profile

... to check the PHP version with the same command we used in the beginning of this tutorial:

which php

Install Composer

Ok. From here on, we can use the documentation of the Drush project, as found on Github. The easiest way to install Drush is by using Composer.

In the terminal, browse to your home directory:

cd ~

Download Composer:

curl -sS https://getcomposer.org/installer | php

Composer install

Create a usr/local/bin directory:

sudo mkdir -p -m 755 /usr/local/bin

And from within the home directory, move the composer.phar to the newly created /usr/local/bin folder:

sudo mv composer.phar /usr/local/bin/composer

Next, we have to put Composer in our PATH, so we can access it globally. Run:

sudo nano ~/.bash_profile

And add the following line:

export PATH="$HOME/.composer/vendor/bin:$PATH"

Then click CTRL + X, then Y and Return (Enter).

In order to see the changes we have to reload the file with the profile we just changed:

source ~/.bash_profile

To test if everything is working well, just run the Composer command:

composer

Install Drush

Next, we can install Drush with one command:

composer global require drush/drush:dev-master

Test by using the next command:

drush status

Drush status

Add the MAMP shell path

Lastly ,we have to add the shell path to OS X. We need this to use the MySQL version of MAMP. Without this step we can use Drush to download a module but when we want to enable a module, we will receive a bunch of errors.

First, check the MySQL path, normally this is /Applications/MAMP/Library/bin. Then add this line to .bash_profile, in the same manner as the other two lines:

export PATH=/Applications/MAMP/Library/bin/:$PATH

The final .bash_profile should look like this:

bash_profile for Drush

Voila, Drush is functional on the localhost and has the right permissions to run all the commands!

Note, before reading the comments and getting confused: this article has already been revised two times. The first version featured an installation of Drush with Pear, the third a manual install and this version (14th of February 2015) has an install with Composer. The installation with Composer is by far the easiest.

Comments

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.