Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

Switching between PHP versions with Homebrew

David Carr

Bash Tutorials Development

    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

     

    Laravel Modules Book by David Carr

    Help support the blog so that I can continue creating new content!

    Subscribe to my newsletter

    Subscribe and get my books and product announcements.

    © 2009 - 2022 DC Blog. All code MIT license. All rights reserved.