How to override the path of PHP to use the MAMP path?

sf_tristanb picture sf_tristanb · Nov 10, 2010 · Viewed 119.1k times · Source

After screwing up entirely my PHP configuration on MAC trying to get the SOAP module working (-bash: /usr/bin/php: No such file or directory ....) I now have to use MAMP but each time I have to type the path

Applications/MAMP/bin/php5.3/bin/php to do command line.

How to just type php instead the entire path on MAC ? I double checked and i do not have a file named .profile nor bash_profile

Thanks

PS: Here's what output echo $PATH :

echo $PATH
/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin

Answer

David Yell picture David Yell · May 18, 2012

In your home folder /Users/David for exmaple, you can create a .bash_profile. In here you can export variables and then add them to your path.

Open up the file to edit it in your favourite editor, I use vim.

Then you can add in your path

export MAMP_PHP=/Applications/MAMP/bin/php/php5.3.6/bin
export PATH="$MAMP_PHP:$PATH"

You want your bit ahead of the $PATH as that already includes /usr/bin which is where the system PHP lives. So the system will always find your MAMP version first.

Save this file and then reboot your Terminal and you'll see that you should get your MAMP version.

To test I use php -v as OSX Lion uses 5.3.10 and my MAMP is using 5.3.6
You can also test using which php which will output the path to your current php executable.