Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jaredhowland/e2a13f58d41d1fb5d4b1c825d191aa25 to your computer and use it in GitHub Desktop.
Save jaredhowland/e2a13f58d41d1fb5d4b1c825d191aa25 to your computer and use it in GitHub Desktop.
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\""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment