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:
you will get an error like this:
Now type drush status and check the PHP location in the output:
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:
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.
Press escape then hold down shift and press z twice to save and quit.
or open up a new terminal window to get the changes to take effect.
and check the PHP location
Drush can now see the PHP location for MAMP
Now if you type
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.
That is it! Now you have Drush 9 working with MAMP.