skip to Main Content

I’m running MacOS Catalina. I installed [email protected] and now i want to change default from [email protected] to [email protected].

I installed [email protected] with this command:

brew install shivammathur/php/[email protected]

I tried to change the default php with this command:

brew link --overwrite --force [email protected]

It output this:

Warning: Already linked: /usr/local/Cellar/php/8.0.2
To relink:
  brew unlink php && brew link php

Afterwards I restart Apache and Terminal but When I get the version of PHP with this command:

php -v

O get this output:

PHP 7.4.15 (cli) (built: Feb  4 2021 12:11:40) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies

Running in output on Terminal:

brew unlink php && brew link php

returns this output:

Unlinking /usr/local/Cellar/php/8.0.2... 24 symlinks removed.
Linking /usr/local/Cellar/php/8.0.2... 24 symlinks created.

After restarting Apache, I get this version of PHP:

PHP 7.4.15 (cli) (built: Feb  4 2021 12:11:40) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies

3

Answers


  1. Chosen as BEST ANSWER

    after uninstalling [email protected] my problem solved

    brew uninstall [email protected]
    

    checking php version:

    PHP 8.0.2 (cli) (built: Feb  4 2021 17:58:53) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v4.0.2, Copyright (c) Zend Technologies
        with Zend OPcache v8.0.2, Copyright (c), by Zend Technologies
    

  2. I have multiple versions of php installed on my mac and will switch it in ~/.zshrc depending on the project I am using.

    Simply uncomment the one you want to use and comment the one you no longer wish to use. You would need to use brew to install the target version.

    Close terminal then re-open for the change to take affect. Or run source ~/.zshrc

    # PHP 7.4
    export PATH="/usr/local/opt/[email protected]/bin:$PATH"
    export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
    
    # PHP 7.3
    #export PATH="/usr/local/opt/[email protected]/bin:$PATH"
    #export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
    
    Login or Signup to reply.
  3. Based on Robert Saylor I exec:

    # PHP 8.0.2
    export PATH="/usr/local/Cellar/php/8.0.2/bin:$PATH"
    export PATH="/usr/local/Cellar/php/8.0.2/sbin:$PATH"
    

    Then checking php version:

    PHP 8.0.2 (cli) (built: Feb  4 2021 17:58:53) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v4.0.2, Copyright (c) Zend Technologies
        with Zend OPcache v8.0.2, Copyright (c), by Zend Technologies
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search