Monday, February 23, 2009

Command line PHP with PEAR on a shared host

On a shared host, you must install PEAR locally, like so (for PEAR 1.4 and above):

pear config-create ~/.php ~/.pearrc


This will create a pear directory in ~/.php, but since you aren't the administrator, you can't just edit the php.ini file and add that to the include path. For php scripts executed by the web server, I don't see any way around it besides a set_include_path at the beginning of every script. For the CLI though, you can copy the php.ini to ~/.php and set the include path there. After creating a wrapper like so:

#!/bin/bash
/usr/bin/php -c ~/.php/php.ini \$@


...you can have PEAR modules included automatically.