Installing PHP7.2 with brew on Mac, The new way
Published 3 years and 3 months ago, Categorized under: Code, Laravel, PHP

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


And PECL installs them at the following path


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/

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.

Share It via: