]> PEAR on Shared Hosting 🌐:aligrant.com

PEAR on Shared Hosting

Alastair Grant | Sun 19 May 2013

The PHP Extension and Application Repository, or PEAR, is an online repository of non-core PHP libraries. These libraries are often referenced in the official PHP documentation, but not bundled as part of the default build.

To use the PEAR libraries you need to install them. This can be done with the useful "pear" command-line utility.

For example, I wanted the "http" package, so to install it I logged onto my shared hosting through SSH and ran:

pear install http

Naturally, my hosting company being 1&1 everything rapidly fell apart with running old versions of PEAR and PHP (defaults to PHP4!).

As PEAR is usually a shared resource in shared hosting, it requires the hosting company to update it - which they are unlikely to do. Luckily you can simply build a local install in your area without affecting the shared install and retain full control.

For 1and1 hosting, there is a couple of tricks you need to do to get the system to ignore the default shared junk. Edit your ~/.profile file and add in these commands:

alias pear='~/pear/bin/pear'
alias php='php6'
export PHP_PEAR_PHP_BIN=/usr/bin/php6

What this does is redirect the "pear" command to your soon-to-be-installed version. The "php" command to the latest binary (NOTE: This is a one and one hosting quirk, it is unlikely to be the same on your hosting), and similarly the PHP_PEAR_PHP_BIN defines where the PHP binary that PEAR should be using (as otherwise mine was falling back to version 4, which is a bit, silly).

Getting PEAR is easy:


wget http://pear.php.net/go-pear.phar

Installing is just as easy:


php go-pear.phar

Set your all your install directories to something under your control. If you setup the first "prefix" entry, you can then use "$prefix" in all your remaining paths as a shortcut.

And that should be about is. To confirm that it is working run "pear -V", this should give you the latest version of PEAR and a recent version of PHP.

Be sure to update your PHP include path in your code to point towards your new directory instead of the shared one.


Breaking from the voyeuristic norms of the Internet, any comments can be made in private by contacting me.