brew search php
brew install php@7.4
brew install php@8.0
brew install php@8.1
brew install php@8.2
brew install php@8.3
brew link php@8.3
php -v
Now that you have all versions installed, you can switch between them effortlessly. Add this function to your .zshrc
:
# Switch PHP version
function sphp() {
Yellow='\033[0;33m'
Color_Off='\033[0m'
brew unlink php@$1 && brew link --overwrite --force php@$1
echo "${Yellow}Validating current PHP Version${Color_Off}"
php -v
}
sphp 7.4
sphp 8.0
sphp 8.1
sphp 8.2
sphp 8.3