Loading...

Switching between PHP versions with Homebrew

David Carr

1 min read - 1st Dec, 2019

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

 

0 comments
Add a comment