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 9C40bIf 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:
//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 acceptIf everything is correct, you can update and upgrade Homebrew with commands:
$ brew update $ brew upgradeWhen 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:
Now, we can follow to install php 7.4 for it at //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 installAnd 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 //github.com/xdebug/xdebug :
$ git clone //github.com/xdebug/xdebug $ cd xdebug $ git checkout 2.8.1 $ phpize $ ./configure --enable-xdebug $ sudo make $ sudo make installAfter 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 xdebugIf everying correct, you will get PHP 7.4 with Xdebug 2.8.1 like the following php -v command output:
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 OKTo switch the PHP CLI to 7.4, first I ran Homebrew's unlink/link command:
$ brew unlink php && brew link phpThis should produce an output similar to this:
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 .zshrcLocate the following (or similar) line...
export PATH=/usr/local/php5/bin:$PATH... and change it to:
export PATH=/usr/local/bin/php:$PATHNote
$ ls -al /usr/local/bin/php /usr/local/bin/php -> ../Cellar/php/7.4.0/bin/php
If you list the PHP executable...... 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 )Liked this article? Share it on your favorite platform.