Skip to content

Instantly share code, notes, and snippets.

@tonning
Created January 19, 2021 11:48
Show Gist options
  • Save tonning/2b64f00ba3f669f30579d7809986f00c to your computer and use it in GitHub Desktop.
Save tonning/2b64f00ba3f669f30579d7809986f00c to your computer and use it in GitHub Desktop.
Switch PHP version in MacOS with Homebrew
installedPhpVersions=('7.1' '7.2' '7.3' '7.4', '8.0')
for phpVersion in ${installedPhpVersions[*]}; do
value="{"
for otherPhpVersion in ${installedPhpVersions[*]}; do
if [ "${otherPhpVersion}" != "${phpVersion}" ]; then
value="${value} brew unlink php@${otherPhpVersion};"
fi
done
value="${value} brew link php@${phpVersion} --force --overwrite; } &> /dev/null && php -v"
alias "php@${phpVersion}"="${value}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment