Zaher Ghaibeh
PHP Backend developer
I've experience in a few PHP Frameworks, such as Laravel, Lumen and Slim (The last two are used for building Microservices/API services).
Installing PHP7.2 with brew on Mac, The new way
Published at Tuesday, April 17, 2018

Now that homebrew has fully deprecated the old PHP channel and merged everything within the code, things have changed. Before you were able to install anything using a command like brew install php- but now it won't work anymore.

The new way is simple and easy (not), so follow me:

  • First, you will need to make sure the old taps or anything old you have (maybe just moves them to another directory).

  • Second, update and clean up your brew installation, run those commands for example:

brew update && brew upgrade
brew doctor

and fix any issue you see.

  • Install PHP via brew by running brew install php which will install PHP 7.2 by default.

  • Now the annoying part (for me), which I can't blame them for it nor I can say anything about, is installing xdebug with pecl , that's correct we are back to use pecl again

pecl install xdebug

After that running php -v will complain about not finding xdebug and that's because PHP load the extensions from a directory while PECL installs them in a different one.

In my case PHP loads them from the following path

/usr/local/Cellar/php/7.2.4_1/lib/php/20170718

And PECL installs them at the following path

/usr/local/Cellar/php/7.2.4_1/pecl/20170718/

My simple solution was to symbolic xdebug file to the path that PHP load by running

cd /usr/local/Cellar/php/7.2.4_1/lib/php/20170718
ln -s /usr/local/Cellar/php/7.2.4_1/pecl/20170718/xdebug.so

So my advice for you is to read the log correctly, as this will help you a lot and spare you a lot of time. Also,

remember to run php -m before installing anything.