Problem
I’d like to test my application on PHP versions 5.3 to 7.0.
Where and how can I install the versions and how can I switch them by running a small script?
Asked by Xaver
Solution #1
If you have both versions of PHP installed, you may use the link and unlink brew instructions to switch between them.
To transition between PHP 7.4 and PHP 7.3, for example.
brew unlink php@7.4
brew link php@7.3
PS: For these commands to work, both versions of PHP must be installed.
Answered by Goke Obasa
Solution #2
This tutorial on how to install and switch PHP versions on OSX is really helpful.
I can change the version like this:
$ sphp 7.0 => PHP 7.0
$ sphp 7.3 => PHP 7.3
$ sphp 7.4 => PHP 7.4
That’s exactly what I’m looking for!
Answered by Xaver
Solution #3
Let’s say we want to upgrade from PHP 7.4 to PHP 7.3.
brew unlink php@7.4
brew install php@7.3
brew link php@7.3
If you encounter the message Warning: php@7.3 is keg-only and requires linking with —force, Then give this a shot:
brew link php@7.3 --force
Answered by itsazzad
Solution #4
Show current version
$ php -v
Change to a newer version (for example, from 5.5.x to 7.0.latest):
$ brew unlink php55
$ brew install php70
Answered by kris
Solution #5
You may easily swap between PHP versions if you install it with homebrew. If you want php56 to refer to Version 5.6.17, simply type:
brew switch php56 5.6.17
Answered by Mark Setchell
Post is based on https://stackoverflow.com/questions/34909101/how-can-i-easily-switch-between-php-versions-on-mac-osx