Secondary menu

Auto-select correct PHP version on commandline from MAMP

aaron's picture

Auto-select correct PHP version on commandline from MAMP

Written by Aaron Stewart on

I think everyone's done it at this point.. They've got some legacy site that needs an older php version, and they switch MAMP over to using PHP 5.2. However, they forget to update their path on the command line and suddenly Drush is using an old version and you're scratching your head as to why.

Well, after a bit of digging, I found a way to auto-select the right version of PHP into your path when you open a new terminal.

It's a simple two-line change to your ~/.bash_profile that does the magic:

PHPVER=$(/usr/libexec/PlistBuddy -c "print phpVersion" ~/Library/Preferences/de.appsolute.mamppro.plist)
export PATH=/Applications/MAMP/bin/php${PHPVER}/bin:$PATH