How to install PEAR on your shared web hosting account
Inside This Article
Use the hosting company's PEAR installation
If you use a shared web hosting, the chances are that it has already installed BEAR Base System. You will need to find out in which directory they are placed. It's very often that the PEAR package you need is not part of the default PEAR installation provided by your hosting company. In this case, you have to install your own.
Step #1: Create new folder.
1.1 Connect to your hosting account via FTP program.
1.2 Create a new folder under your account home directory called pear (it is on the same level as public_html folder).
It's a good idea to create include directory one level above the public_html folder so that sensitive files are placed outside the publicly accessible web folder (where public_html is) - just an extra precaution.
To understand fully about how to create include path, refer to article Five ways to create include path for PHP.
Step #2: Add new PEAR package.
2.1 Download the PEAR package you need.
For illustration purpose, here we assume you need PEAR Text_Highlighter package.
The file I downloaded was Text_Highlighter-0.7.1.tgz
2.2 After unzip the package, rename the folder Text_Highlighter-0.7.1 to Text
To unzip, you may want to use popular open source file archiver 7-Zip.
It looks like this after rename:
2.3 Upload the entire folder Text to pear folder you created in step 1.2 above. Note that folder Text is now inside folder pear.
Step #3: Add include path for PEAR package.
3.1 Contact your hosting company to find out where their PEAR library is stored. Normally it should be at /usr/local/lib/php
3.2 Add include path in either php.ini or .htaccess file.
Depends on how your web hosting company set up their web server, you can include PEAR in two different ways:
Step #4: Test if PEAR has been installed correctly.
We are going to use PEAR's text_highlighter class to display colored PHP code on a web page.
4.1 Create the style sheet.
Find the file sample.css in folder Text which you renamed in step 2.2 and upload it to your website root directory.
On GeeksEngine, it's copied to http://www.geeksengine.com/sample.css
4.2 Create a PHP page and save it as test-pear.php in your localhost website.
On GeeksEngine, it's at http://www.geeksengine.com/test-pear.php
4.3 Open test-pear.php in your text editor and add the following code. The code displays colored PHP code on a web page.
4.4 Display test-pear.php page.
Open your web browser and view test-pear.php on your site. If you can see the colored PHP code as below, you have successfully installed PEAR base library.
To use any other packages, just download and add them to pear directory which is on your web host home directory.
Copyright © 2017 GeeksEngine.com. All Rights Reserved.
This website is hosted by HostGator.
No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.