Update PHP to 7.4 macOS Catalina with brew

PhpMacosHomebrewPhp 7.4

Php Problem Overview


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

Php Solutions


Solution 1 - Php

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

Solution 2 - Php

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 php@7.3
brew link php@7.4

Solution 3 - Php

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

Solution 4 - Php

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 php@7.4
brew services restart php
brew unlink php@8.1
brew link php@7.4
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 5 - Php

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

Solution 6 - Php

  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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmeezView Question on Stackoverflow
Solution 1 - PhpchenruiView Answer on Stackoverflow
Solution 2 - PhpSalinesView Answer on Stackoverflow
Solution 3 - PhpThiên TrầnView Answer on Stackoverflow
Solution 4 - PhpShimantoView Answer on Stackoverflow
Solution 5 - PhpJayeola FrancisView Answer on Stackoverflow
Solution 6 - PhpMohammad Rakibul IslamView Answer on Stackoverflow