To start using a PEAR Package, first install it into your hosting account and then enable it for the PHP application/script.
Installing a PEAR Package
Automatic Installation in cPanel
PEAR Packages are automatically installed in cPanel -> (Software) PHP PEAR Packages. In this menu you can view a list of all installed packages or add new ones.
The packages are stored into the following directory:
/home/cpuser/php
(cpuser – cPanel username)
Manual Installation via FTP or File Manager
Another option is uploading the PEAR package in your hosting account manually. A full list of all downloadable packages is available at: http://pear.php.net/packages.php
Afterwards, you can upload the package into your hosting account via FTP or File Manager.
Note: We do not recommend this option for installation. Simply uploading the package files into your hosting account will not install any dependencies (such as other PEAR packages). |
Using a PEAR Package
After the package has been installed into your hosting account, you first need to specify this in the PHP application/script.
Normally that can be done with the appropriate PHP functions such as: include(), include_once() or require_once(). For example:
require_once '/home/cpuser/php/PHPUnit.php';
When the PEAR package directory is not included in the PHP system path, you need to type in the full path to the executable file.
Adding the PEAR Package Directory to the PHP System Path
The include_path directive in php.ini is used to specify directories where the require, include, fopen(), file(), readfile() and file_get_contents() functions will search for files. The syntax for this path will be identical to the PATH environment variable.
The php.ini file which is used by the current PHP version on the hosting account can be easily modified in cPanel -> PHP Manager by SuperHosting -> Advanced Settings. |
If the PEAR package is installed in the /home/cpuser/php directory, you should only add “/home/cpuser/php” to the include_path in php.ini:
include_path = ".:/home/cpuser/php"
If there is a value already entered for this directive (for example “.:/usr/lib/php:/usr/local/lib/php”) then you should add the PEAR package path with a colon in front. For example:
include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/cpuser/php"
After the package directory has been added to include_path in php.ini, а certain package functionality can be called only with the name of its executable file. For example:
require_once 'PHPUnit.php';
Setting up include_path Directly in a PHP Script
The include path can be set up or changed directly in the called script with a set_include_path() function or ini_set() that is properly working in all available PHP versions. For example:
ini_set("include_path", '/home/cpuser/php:' . ini_get("include_path") );