75

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

1

7 Answers 7

194

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

Sign up to request clarification or add additional context in comments.

10 Comments

This solution works perfectly in MacOS BigSur.
Instead of link --force I had to do brew link --overwrite [email protected]
yeah, add --overwrite to the OP (it would consider the existing php links), thanks Jannie!
Works on BigSur 11.4
I'm doing this in Catalina but export PATH="/usr/local/opt/[email protected]/bin:$PATH" seems to take forever.
|
23

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]

4 Comments

thanks but after trying above, it still show PHP 7.3.11? I need to update to 7.4 because of composer's dependencies.
@meez. after services restart ?
After brew unlink [email protected] I get Error: No such keg: /usr/local/Cellar/[email protected] ?
@meez run brew doctor
9

It seems that PHP v7.4 is no longer available on the default Homebrew repository. However, you can add an additional Tap (repository) and still install it:

  1. brew tap shivammathur/php (Adds this repo)
  2. brew install [email protected]

(I think this qualifies as an answer)

Comments

8

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" 

Comments

1

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

1 Comment

Oddly enough, this did the trick even though I've linked/unlinked taps various times successfully from the VS Code terminal.
0
  1. I move to directory by: cd /usr/local
  2. Find the file location by: find /usr/local/ -name libphp7.so. (Then get the file location at: /usr/local//Cellar/[email protected]/7.4.23/lib/httpd/modules/libphp7.so. I copy this.)
  3. I open the file by: sudo vim /etc/apache2/httpd.conf
  4. Look for the line by: /libphp7.so
  5. Uncomment the line and update the line by: LoadModule php7_module /usr/local//Cellar/[email protected]/7.4.23/lib/httpd/modules/libphp7.so
  6. Restart apache by: sudo apachectl restart
  7. Verify PHP by accessing http://localhost/phpinfo.php

Comments

-1

I recently faced this issue, all the suggestion here didn't work until I ran:

xcode-select --install

Then ran the command I was trying before and the error stopped, for my case it was php

dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib Referenced from: /usr/local/opt/[email protected]/bin/php Reason: image not found zsh: abort php -v

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.