Skip to content

Instantly share code, notes, and snippets.

@yaronuliel
Last active June 4, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaronuliel/f3edb0d09ec8aefacc8ec6be99b4d29a to your computer and use it in GitHub Desktop.
Save yaronuliel/f3edb0d09ec8aefacc8ec6be99b4d29a to your computer and use it in GitHub Desktop.
HomeBrew PHP Version select script
# Add this function to your ~/.bash_profile file
# To show current linked version, run: `phpversion`
# To link another version, run: `phpversion VERSION` (e.g. `phpversion 7.2`)
phpversion() {
# Get currently installed HomeBrew php version (ignoring system php)
local current_php_version=$(/usr/local/bin/php -r "echo PHP_VERSION;" 2>/dev/null | awk -F'.' '{print "php@" $1 "." $2}')
# If no argument passed - Present the current version
if [ -z "$1" ]; then
echo "Current: $current_php_version"
else
[ ! -z "$current_php_version" ] && brew unlink $current_php_version
brew link --force "php@${1}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment