brew search php
brew install php@7.4brew install php@8.0brew install php@8.1brew install php@8.2brew 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.4sphp 8.0sphp 8.1sphp 8.2sphp 8.3