Wednesday, April 10, 2013

Install PECL extensions with Homebrewed PHP on Mac OS X Mountain Lion

I needed to use the HTTPRequest class that comes as a PECL extension to PHP. This was easier than I thought. If you followed my instructions for installing PHP with Homebrew, then installing the PECL extensions should be even easier. Here's how:

Open up the Terminal and do:

$ pecl list-all

just as a sanity check to make sure you have PECL installed from your Homebrew installation of PHP. You will see a list of all available PECL packages, and, potentially after some "Warnings" from bugs in the PEAR code, you'll notice that "pecl/pecl_http" is in the list.

Before you can install anything with pecl, you need autoconf. It helps to build in the environment with which we're working. Just do:

$ brew install autoconf

Then install your favorite PECL extension (in my case, pecl_http):

$ pecl install pecl_http

Then a whole bunch of code garbage will fly past the screen. In a minute or two, some config options will appear. Press "return" to accept the defaults in brackets. When it's finished, you'll know.

If you got a fatal error during install, try running under sudo. If you still get an error, wait a day or two and maybe they'll push a bug fix?

Then just restart your web service (I just reboot my computer) and you're done!