Skip to content

Instantly share code, notes, and snippets.

Last active Jun 4, 2018
What would you like to do?
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"
[ ! -z "$current_php_version" ] && brew unlink $current_php_version
brew link --force "php@${1}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment