How do i update php to 7.4 on mac?

So, you’re still using macOS Sierra because of old mac hardware or whatever reason. You can still using Homebrew, while you will get the following warning:

Warning: You are using macOS 10.12.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this old version.

Read above warning carefully before continue, as you will responsible yourself if experiencing issues.

First, if you are still want to try it, what you need to do is verify that you have latest Xcode 9.2 that support macOS Sierra:

$ /usr/bin/xcodebuild -version

Xcode 9.2
Build version 9C40b

If you’re still using older version, you can first remove the Application/Xcode directory and download manually (yes, manually) as you cannot update via App Store from the following URI:

https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_9.2/Xcode_9.2.xip

That’s about 5GB file. After downloaded, you can extract to /Application that will be about 10GB contents, if you’re using old mac hardware, it may take a while. After it extracted, you need to accept its license by run command:

$ sudo xcodebuild -license accept

If everything is correct, you can update and upgrade Homebrew with commands:

$ brew update
$ brew upgrade

When done, you can verify that some “probably” dependencies needs install/update with run brew doctor until it only show 1 warning, which is outdated operating system:

$ brew doctor

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You are using macOS 10.12.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this old version.

Now, we can follow to install php 7.4 for it at https://getgrav.org/blog/macos-catalina-apache-multiple-php-versions which the example is for macOS Catalina, that the steps can be used in macOS Sierra.

On PHP Installation section steps, run install php 7.4 command via Homebrew:

$ brew install 

And that’s it, if everything is correct, now you have PHP 7.4.

Bonus

You can add Xdebug extension with clone latest xdebug from its repository at https://github.com/xdebug/xdebug :

$ git clone https://github.com/xdebug/xdebug
$ cd xdebug
$ git checkout 2.8.1
$ phpize
$ ./configure --enable-xdebug
$ sudo make
$ sudo make install

After it, add the following line to /usr/local/etc/php/7.4/php.ini

zend_extension="/usr/local/Cellar/php/7.4.0/pecl/20190902/xdebug.so"

zend_extension pointed to real location of xdebug.so installed above.

The alternative can be via pecl command:

$ sudo pecl install xdebug

If everying correct, you will get PHP 7.4 with Xdebug 2.8.1 like the following php -v command output:

How do i update php to 7.4 on mac?

On Mac, PHP can be easily upgraded to 7.4 with Homebrew. However, the command line may continue to show the previous version. Here's how to fix that.

Upgrade to PHP 7.4 with Homebrew on Mac is a very succinct article by @brendt_gd that boils it down to two simple commands: brew update and brew upgrade php.

The problem I ran into was that my PHP CLI in the terminal remained linked to the previous version. Checking the version, before and after running the brew command produced the same result:

$ php -v
PHP 7.2.9 (cli) (built: Aug 21 2018 07:42:00) ( NTS )

Just to make sure 7.4 was actually installed, I ran the upgrade command again, then checked the actual location of PHP 7.4:

$ brew upgrade php
Warning: php 7.4.0 already installed

$ ls /usr/local/etc/php/7.4
OK

To switch the PHP CLI to 7.4, first I ran Homebrew's unlink/link command:

$ brew unlink php && brew link php

This should produce an output similar to this:

Unlinking /usr/local/Cellar/php/7.X... XX symlinks removed
Linking /usr/local/Cellar/php/7.4.0... 24 symlinks created

Finally, you need to export the proper path variable for the PHP executable in either .bashrc or .zshrc. These are typically located in your home (~) folder:

$ cd ~
$ vi .zshrc

Locate the following (or similar) line...

export PATH=/usr/local/php5/bin:$PATH

... and change it to:

export PATH=/usr/local/bin/php:$PATH

Note
If you list the PHP executable...

$ ls -al /usr/local/bin/php
/usr/local/bin/php -> ../Cellar/php/7.4.0/bin/php

... you'll notice that /usr/local/bin/php is a symlink pointing to /usr/local/Cellar/php/7.4.0 which is the same location that was linked by Homebrew above.

Finally, run source .zshrc to get the terminal to update its configuration.

For good measure, close the terminal window and open a fresh one. If you now run php -v you should be rewarded with this:

$ php -v
PHP 7.4.0 (cli) (built: Nov 29 2019 16:18:44) ( NTS )
Mac PHP

Liked this article? Share it on your favorite platform.

How do i update php to 7.4 on mac?

How do I update PHP 7.4 on Mac?

6 Answers.
brew install [email protected]..
brew link --force --overwrite [email protected]..
brew services start [email protected]..
export PATH="/usr/local/opt/[email protected]/bin:$PATH".
export PATH="/usr/local/opt/[email protected]/sbin:$PATH".

How do I update PHP version on Mac?

To update the PHP version, update the brew using the command brew update . Then, use the command brew upgrade php . It upgrades the current version to the latest version of PHP. Then, restart the webserver to see the changes.

How do I upgrade PHP to 8.0 on Mac?

Upgrading with Homebrew.
Normal upgrade. brew upgrade php..
Upgrade with shivammathur/homebrew-php. brew tap shivammathur/php brew install shivammathur/php/[email protected]. To switch between versions, use the following command: brew link --overwrite --force [email protected]. ... .
Next steps. Check the current version by running php -v : php -v..

How do I check my PHP version on Mac?

The php -v command works on Linux, macOS, Windows, and other supported systems. Its output contains the PHP version number, build date, and copyright information. Note: If there is more than one PHP version installed on the server, the php -v command shows the default command-line interface (CLI) version.