Getting an HTTP_Request class was pissing me off. So it seems like you can’t install PECL classes on your php install because of rights issues on a shared hosting environment.
BUT, you can get PEAR classes installed through the cPanel, using the PHP PEAR Packages link. I was adding the HTTP_Request package (HTTP_Request2 won’t install because there is no stable release as of yet).
But even after the install, the classes could not be found. Like when I did require_once(‘HTTP/Request.php’) I was getting the classic not found warning and error:
Warning: include(HTTP/Request.php) [function.include]: failed to open stream: No such file or directory
Warning: include() [function.include]: Failed opening ‘HTTP/Request.php’ for inclusion
Fatal error: Class ‘HTTP_Request’ not found
You have to edit the php.ini (or ini_set the include_path ) to include :/home/yourusername/php, or in my case the home directory is now home3 for some reason, with some weird aliasing allowing for home I think. The PEAR packages install to /home/yourusername/php, so this needs to be added to the include path.
If you still get:
PHP Fatal error: main(): Failed opening required ‘PEAR.php’
Then your include_path may be missing :/usr/lib/php, this is the main (not your local user) php lib folder that, I think, has the main PEAR files (The ones that your local PEAR package installs like HTTP_Request will be calling). So when you install a PEAR package via the cPanel, it puts them in /home/yourusername/php, and those files will need to know about the main PEAR install in /usr/lib/php by having /usr/lib/php in the include path.
2 thoughts on “Using PEAR classes with bluehost php – Edit your include_path”
Thank you for your tip, I’ve been trying to install a program called VTCalendar and it requires PEAR but I keep getting DB errors because of PEAR not installing properly. Where do you actually add the include text in the .ini file? Any help would be appreciated!
Understanding the include_path is (a) KEY to using php. I’d lookup some entries on google. I’ll just summarize to avoid repeating data that is available all over the web. I have to admit, though, that there isn’t a really nice,easy article explaining the basics of the php include_path. But in a nutshell:
Look for the line in the php.ini (it should already be in there on install, but may be comented out). It will say ‘include_path = .:/somepath:/anotherpath’. You need to append ‘:/home/yourusername/php’ and possibly ‘:/usr/lib/php’ to the end of this list. The php.ini for your bluehost should be in your webroot. The PEAR install should have created a folder ‘php’ or added to it, in the folder ‘/home(3?)/yourusername’. If you don’t have a php folder in ‘home(3?)/yourusername’ then you need to install PEAR through the CPanel, or find out where the thing installed it in your user folder/shared server space.
You can also set this manually on one php script page using ini_set(‘include_path’, ‘.:/yoursdesiredpath:/yourdesiredpath2’);
It took me forever to use the include_path effectively. Note the syntax, the . means ‘look in the current directory first’ and then each other path is separated by a :. These are all the places php will look for included/required php files/classes. Essentially the php_include path is like your php mappings, telling php where to find files you will include in your scripts. With coldfusion it was a lot clearer with a gui server admin that had you add each server mapping. It took me a bit to translate ‘include_path’ to ‘php server mappings’ in my mind. To begin with, I had been used to using includes for templating purposes only.
Also note that the VTCalendar stuff may have screwy interfacing with your php include_path settings.