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. 

Replies

You are reading an archived discussion.

Related Posts

i want to learn coding for software development and i am new at it , i don't have any knowledge of language but i want to start , i am...
Is there any chance of opting for MS  from aboard or  M.tech from India?
I have completed my class12.Now  I am doing with engineering cse branch.what should I learn ?so I can be at a good position in future.