Friday, September 23, 2011

Installing PHP's Pear on MacOS Lion

This blog post will cover the installation process of PHP's pear on MacOS Lion.

Googling revealed several blog posts for Leopard.  The first of which I encountered was, How To Install PEAR in Mac OS X Leopard.  The first instruction is not consistent with the version of PHP distributed with Lion, which prompted this blog article.  I received the following error:
Sorry!  Your PHP version is too new (5.3.6) for this go-pear.
Instead use http://pear.php.net/go-pear.phar for a more stable and current
version of go-pear, more suited to your PHP version.
If you are using Lion, follow these instructions for completing the installation process for pear.

The first step is downloading the pear PHAR.  Make sure that you execute this command in a directory where you have write permissions.  I chose my home directory.
curl http://pear.php.net/go-pear.phar > go-pear.phar
Next, run go-pear to complete the installation process of the library.
sudo php -q go-pear.phar
When prompted with the installation locations, change the "Installation base" setting to /usr/local/pear.  Press enter, and watch the installation complete.

As documented in the installation instructions in the posting, How To Install PEAR in Mac OS X Leopard, you will need to create the php.ini.  (I am documenting the steps here for completeness.)

Copy php.ini.default to php.ini.
sudo cp /etc/php.ini.default /etc/php.ini
Next, edit the php.ini file.
sudo vi /etc/php.ini 
Lastly, update the php.ini configuration to include following line to reference pear libraries.
include_path = ".:/usr/local/pear/share/pear"
Restart your Apache server or run your PHP script.  Everything should work as expected.