Skip to content

Instantly share code, notes, and snippets.

Last active February 6, 2020 19:06
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Make all MAMP PHPs available on command line, and default to the latest
# Henry Bley-Vroman, 2019
# Usage
# Paste or source this into your shell profile.
# Requires macOS and that your shell supports [[ ]] and '<string> == <starting substring>*'
# (Bash, Zsh, Ksh etc)
# alias php to the latest PHP installed with MAMP
MAMP_PHP__LATEST=$(ls /Applications/MAMP/bin/php/ | sort -V | tail -1)
alias php="/Applications/MAMP/bin/php/${MAMP_PHP__LATEST}/bin/php -c \"/Library/Application Support/appsolute/MAMP PRO/conf/${MAMP_PHP__LATEST}.ini\""
# alias pear and pecl to the MAMP copies
alias pear="/Applications/MAMP/bin/php/${MAMP_PHP__LATEST}/bin/pear"
alias pecl="/Applications/MAMP/bin/php/${MAMP_PHP__LATEST}/bin/pecl"
# create aliases for every version of PHP installed with MAMP
# for every file in the MAMP php directory
for phpv in $(ls /Applications/MAMP/bin/php); do
# if the item is a php version (not, say browscap.ini)
if [[ "$phpv" == php* ]]; then
# reformat e.g. php7.3.1 to php7_3_1
php_v=$(echo "$phpv" | tr '.' '_')
# for create an alias named like php7_3_1_mamp
alias "${php_v}_mamp"="/Applications/MAMP/bin/php/${phpv}/bin/php -c \"/Library/Application Support/appsolute/MAMP PRO/conf/${phpv}.ini\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment