skip to Main Content

I have High Sierra installed and it comes with php 7.1. During the environment I ended up being able to upgrade to php7.2 but wasn’t able to document it, so I dont exactly know what I did. Now, I am trying to switch to php 7.3

Using brew, I ran the following commands:

brew unlink [email protected]

brew services install [email protected]

brew link [email protected]

If I restart my terminal and check for the php version:

php -v

I still see 7.2.25 version and not 7.3 as I desire

I also tried with a node package that I found in this link here but no success.

How do I successfully switch between php versions?

5

Answers


  1. Here is my installation script:

    Now my output would be as:

    $ php -v
    PHP 7.2.25 (cli) (built: Nov 22 2019 10:27:28) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.2.25, Copyright (c) 1999-2018, by Zend Technologies
    

    I think the PATH environment setup is something matters. And it does show in instructions as part of the installation process though.

    Hope it helps resolving your issue.

    Login or Signup to reply.
  2. @chenrui’s is perfect. I just had to create the sbin directory additionally as well.

    You can find it [question]: brew link php71: Could not symlink sbin/php-fpm

    Login or Signup to reply.
  3. Since I had to face this issue as well, let me share how to make this work.
    If you have to switch back and forth on mac then this is what works for me.

    Let’s say you have multiple PHP versions installed 7.2 and 7.4

    Services List and Current version

    Now my current PHP version is 7.4 & I have to switch back to 7.2, steps will be.

    1. brew unlink [email protected] && brew link [email protected] --force

    2. nano ~/.zshrc -> Update Export Path From 7.4 to 7.2

      zshrc file

    3. Save It.

    4. brew services stop [email protected]

    5. brew services start [email protected]

    enter image description here

    Voila.
    To go back to 7.4 Run brew unlink [email protected] && brew link [email protected] --force & uncomment export files. That’s it.

    Login or Signup to reply.
  4. Until I restarted Terminal I kept seeing the old version.

    Login or Signup to reply.
  5. Open the terminal then run

    nano ~/.zshrc
    

    In the file that you open, you’ll find the exported path of PHP as follows:

    #export PATH="/usr/local/opt/[email protected]/bin:$PATH"
    #export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
    export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
    

    Then comment the old version by adding # at the first of line and save file CTRL+x

    after that close the terminal or open new one then get the php version again

    php --version
    

    I hope you have completely switched to the new PHP version

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search