How can I easily switch between PHP versions on Mac OSX?
Example: Let us switch from php 7.4 to 7.3
brew unlink php@7.4
brew install php@7.3
brew link php@7.3
If you get Warning: php@7.3 is keg-only and must be linked with --force
Then try with:
brew link php@7.3 --force
I found this very good tutorial on how to install and switch php versions on OSX.
I can switch the version like
$ sphp 7.0 => PHP 7.0
$ sphp 7.3 => PHP 7.3
$ sphp 7.4 => PHP 7.4
Exactly what I want!
If you have both versions of PHP installed, you can switch between versions using the link
and unlink
brew
commands.
For example, to switch between PHP 7.4 and PHP 7.3
brew unlink php@7.4
brew link php@7.3
PS: both versions of PHP have be installed for these commands to work.
Using brew
Show current version
$ php -v
Change to different version
(eg. changing from 5.5.x to version 7.0.latest) :
$ brew unlink php55
$ brew install php70