View Feed
group-icon
PHP Programmers
Community for PHP Programmers : Ask questions, doubts and help each other get better at PHP
270 Members
Join this group to post and comment.
Kaustubh Katdare
Kaustubh Katdare • Jul 11, 2018

How to Install PHP 7.2+ On MacOS with Brew 1.5 - Guide

I'm writing a small tutorial to help fellow engineers who are looking to install PHP 7.2+ on MacOS with Homebrew (brew v.1.5). Let me put a disclaimer - I'm not an expert and have collected the following information from multiple sources on the Internet. It worked for me and hope it will, for you too.

It looks like after the release of Homebrew 1.5 a lot of things have changed with the way PHP installation works. The most regular command :

brew install php72-xdebug 

does not work anymore and throws -

Error: No available formula with the name "php72-xdebug" error. Keep in mind that with Brew 1.5, the tap homebrew/php is no longer functional. It seems to have migrated to homebrew/core. 

Here's how to install -

1. First run `brew update` to update your brew install.

2. Install PHP7.2 by running `brew install php@7.2`

3. Once installed, we'll now want to change the default PHP version reported by OSX in terminal -

Run `php -v'

It should output the current version of PHP installed on your MacOS. In order to change it to PHP 7.2 or any other version, do the following -

1. Make sure that file `.bash_profile` exists inside ~/. Do `cd ~/` and then run `ls -al`. 

2. Run `nano .bash_profile`. Add the following line to it

`export PATH=/usr/local/Cellar/php/7.2.7/bin:$PATH`

(Ignore the backticks). Save the file.

3. Then run `source ~/.bash_profile` so that new changes take effect. 

4. Run `php -v` again, it should now report

PHP 7.2.7 (cli) (built: Jun 22 2018 06:27:50) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

    with Zend OPcache v7.2.7, Copyright (c) 1999-2018, by Zend Technologies

I hope this helps. You can use the same technique to install other dependencies required for your development environment. 

If you have questions, shoot them below. I'll try to answer to the best of my abilities. 

Share this content on your social channels -