Skip to main content

How to get Drush 9 working with MAMP

By Sue Johnson

If you are using Mac OS X and install Drush 9 and want to use MAMP for your development, you will need to do a bit of extra work to get it working.

If you do not have Drush 9 installed, see how to install it here https://suesdesign.co.uk/install-composer-and-drush-on-mac-os-x/. You will also need to start MAMP and have Drupal 8 installed.

Navigate to your sites/default directory on your Drupal installation.

If you try to put your Drupal website into maintenance mode using the command:

drush sset system.maintenance_mode 1

you will get an error like this:

Command "sset" is not defined.

Now type drush status and check the PHP location in the output:

PHP binary : /usr/bin/php

You will see that the PHP version is the one used by the system, not the one used by MAMP.

Check which PHP version MAMP is using. In this case, it is php7.2.1

To change the PHP to the version MAMP is using, you will have to add it to your PATH. Open up .bash_profile. You can do this with any text editor. To use Vim type:

vim ~/.bash_profile

The file will open up.

Now press i (for insert mode) and copy and paste this, substituting the PHP version with the one your version of MAMP is using.

export PATH="/Applications/MAMP/bin/php/php7.2.1/bin:/Applications/MAMP/Library/bin:$PATH"

Press escape then hold down shift and press z twice to save and quit.

Now type

source ~/.bash_profile

or open up a new terminal window to get the changes to take effect.

Type

drush status

and check the PHP location

PHP binary : /Applications/MAMP/bin/php/php7.2.1/bin/php

Drush can now see the PHP location for MAMP

Now if you type

drush sset system.maintenance_mode 1

Into your terminal, you will no longer get an error and your Drupal website will be in maintenance mode. To take it out of maintenance mode, type the following.

drush sset system.maintenance_mode 0

That is it! Now you have Drush 9 working with MAMP.

All comments will be held in a moderation queue. A selection will be published.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.