How to use MAMP’s PHP in Terminal by adding it to $PATH

If you already have PHP installed and running with MAMP on MacOS, and get the following with zsh installed

$ which php
$ zsh: command not found: php

You need to reference the MAMP version of PHP in your $PATH

Open terminal and edit your bash profile with

sudo nano ~/.bash_profile 

and add the following, change your PHP version number, shown here as “7.4.21” to match the version you are using, shown in the MAMP control panel.

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

Reload your bash profile with

$ source ~/.bash_profile

and try

$ php --version

and you should get

PHP 7.4.21 (cli) (built: Oct  1 2021 11:18:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Was this article helpful?
YesNo