Simple function to do everything needed to switch easily php version
Add this function in your .zshrc file:
# Switch PHP version
switch-php() {
readonly port=${1:?"Please specify php version"}
valet use php@$1
brew link --force --overwrite php@$1
brew services restart php@$1
echo -n > ~/.switch-php
echo 'export PATH=''"/usr/local/opt/php@'$1'/bin:$PATH"' >> ~/.switch-php
echo 'export PATH=''"/usr/local/opt/php@'$1'/sbin:$PATH"' >> ~/.switch-php
composer global update
omz reload
source ~/.switch-php
php -v
}
Switch to PHP version
switch-php version
# example switch-php 8.0