Update PHP to 7.4 macOS Catalina with brew

54,883

Solution 1

try:

brew update
brew upgrade php
php -v
brew services start php

or

brew services restart php

if you use apache server:

sudo apachectl restart

if you use ngnix

sudo nginx -s reload

Edit:

brew unlink [email protected]
brew link [email protected]

Solution 2

You can find my similar answer for [email protected].

Solution 3

If anyone want to downgrade php from latest 8.1.2 to 7.4 on systems demand, try the below commands with homebrew: Installing PHP 7.4 :

brew install [email protected]
brew services restart php
brew unlink [email protected]
brew link [email protected]
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc

Or

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

Solution 4

Using terminal of MacOS. Don't use terminal in vscode.

Share:
54,883
meez
Author by

meez

Updated on February 08, 2022

Comments

  • meez
    meez about 2 years

    I try to update my PHP version to 7.4 on macOS Catalina with brew.

    I did brew install [email protected]

    If I check my version php -v, I still see the old version PHP 7.3.11?

    What do I have to do?

    Update:

    After brew doctor I get:

    Warning: Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin. Consider setting the PATH for example like so: echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.profile

  • meez
    meez over 3 years
    thanks but after trying above, it still show PHP 7.3.11? I need to update to 7.4 because of composer's dependencies.
  • Salines
    Salines over 3 years
    @meez. after services restart ?
  • meez
    meez over 3 years
    After brew unlink [email protected] I get Error: No such keg: /usr/local/Cellar/[email protected] ?
  • Salines
    Salines over 3 years
    @meez run brew doctor
  • juanitourquiza
    juanitourquiza over 3 years
    This solution works perfectly in MacOS BigSur.
  • Jannie Theunissen
    Jannie Theunissen over 3 years
    Instead of link --force I had to do brew link --overwrite [email protected]
  • chenrui
    chenrui over 3 years
    yeah, add --overwrite to the OP (it would consider the existing php links), thanks Jannie!
  • Ben Fransen
    Ben Fransen almost 3 years
    life saver on BigSur!
  • jo-chris
    jo-chris over 2 years
    96 upvotes is not enough! Thank you! Works on BigSur 11.4
  • Andres SK
    Andres SK over 2 years
    I'm doing this in Catalina but export PATH="/usr/local/opt/[email protected]/bin:$PATH" seems to take forever.
  • M Uzair Qadeer
    M Uzair Qadeer over 2 years
    it's good and working well on OSX Monterey
  • Nenad Kaevik
    Nenad Kaevik over 2 years
    Works like a charm on BigSur
  • Justin Hammond
    Justin Hammond over 2 years
    Oddly enough, this did the trick even though I've linked/unlinked taps various times successfully from the VS Code terminal.
  • Xab Ion
    Xab Ion almost 2 years
    Works perfectly on macOS Catalina. Thanks.