With Homebrew it's possible to have multiple versions of PHP installed at once, to switch which version is active unlink the current version and link the desired version.
Switch from 7.4 to 7.3
brew unlink php@7.4 && brew link --force --overwrite php@7.3
Switch from 7.3 to 7.4
brew unlink php@7.3 && brew link --force --overwrite php@7.4
Since you may want to do this frequently it's more convenient to create a function to do this.
Create a function to your bash/zshrc profile
switchphp() {
brew unlink php && brew link --force --overwrite php@$1
}
This will unlink PHP and relink to the specified version.
Usage:
switch to PHP 7.4
switchphp 7.4
switch to PHP 7.3
switchphp 7.3
Top comments (2)
Thanks.
Does this effect the CLI PHP only? Meaning, would I still need to reconfigure php-fpm or my local web server config to use the different versions?
I have this in my bash profile:
Which takes care of linking to the PHP version I believe so it should work for both. I tend to use PHP's built in web server locally so the command line version works fine.