How to use PEAR in your web hosting account


EXPERIENCING PROBLEMS WITH OUR SERVICES? RUN A DIAGNOSE FIRST TO SAVE YOURS AND OUR TIME

Added: 10.03.2014 23:26:29     Last updated: 03.06.2017 21:38:34

You can install any PEAR packages you might need as shown in the guide Installing PEAR packages in cPanel. The PEAR packages path must be added in include_path for you to be able to make use of them in PHP script. In the guide Installing PEAR packages in cPanel you can see a path to the PEAR packages in step 2 point 1. You can add this in two ways:

  1. Via php.ini file
    The guide Configuration of php.ini shows how to set up a file like this. To add a path to the packages, the following line must be added to the php.ini file:

    include_path = '.:/home/ttesting/php:/usr/lib/php:/usr/local/lib/php';

    Here, ":/home/ttesting/php" is added to include_path (the rest of include_path is standard for all web hosting accounts). The path to the packages should be added first in include_path after "." and it is important to note that every path in include_path is separated with the character ":".
     
  2. Via ini_set()
    include_path can also be set via the PHP code via the ini_set() function in PHP. The following line must in this case be added to the PHP code:

    ini_set('include_path', '.:/home/ttesting/php:/usr/lib/php:/usr/local/lib/php');

The difference between the two methods is that all scripts will include the PEAR packages if you use the php.ini file, while it will only be the code that is run after ini_set() which will include the PEAR packages in the last method.

Example:
To use the PEAR package, the Benchmark which was installed in the guide Installing PEAR packages in cPanel you will only need to add the following PHP code in your scripts:

require_once('Benchmark/Timer.php');