24/7/365 Support(866) 96-GATOR
  1. Knowledge Base
  2. >
  3. Advanced Troubleshooting
  4. >
  5. PEAR Management

PEAR Management

About PEAR

The PHP Extension and Application Repository, or PEAR, is a repository of PHP software code. Its purpose is to re-use code that performs common functions (e.g., Mail.php).

Paths for PEAR command

Depending upon the server, the path that the system-wide PEAR is installed at will be one of the following locations:

/opt/cpanel/ea-php54/root/usr/bin/pear
/opt/cpanel/ea-php55/root/usr/bin/pear
/opt/cpanel/ea-php56/root/usr/bin/pear
/opt/cpanel/ea-php70/root/usr/bin/pear
/opt/cpanel/ea-php71/root/usr/bin/pear
/opt/cpanel/ea-php72/root/usr/bin/pear

Or

/opt/php52/bin/pear
/opt/php53/bin/pear
/opt/php54/bin/pear
/opt/php55/bin/pear
/opt/php56/bin/pear
/opt/php70/bin/pear
/opt/php71/bin/pear

Please attempt the version you wish to use from the first group and if the binary doesn't exist, then try the version you are interested in from the second group.

Install your own local PEAR instance

First, create a local configuration file in a file in your home directory named ".pearrc". Be sure to include the correct PEAR path above for the version of PHP you will be using the modules with.

The following commands uses PEAR from PHP 7.0.x.

/opt/cpanel/ea-php70/root/usr/bin/pear config-create ~/ .pearrc

If that binary doesn't exist on the server, then try:

/opt/php70/bin/pear config-create ~/ .pearrc

At this point, you should see a significant amount of text output, and at the end see something like:

Successfully created default configuration file "/home/(yourusername)/.pearrc"

Next, create a directory structure based on a subdirectory of your home directory named pear that contains all of the packages that you install. You will then have a local version of PEAR that supersedes the system's copy:

/opt/cpanel/ea-php70/root/usr/bin/pear install -o PEAR

Be sure to add $HOME/pear to the beginning of your $PATH (typically in ~/.bash_profile):

$ grep PATH ~/.bash_profile
PATH=$HOME/pear:$PATH:$HOME/bin
export PATH

Then, apply the changes to your local session:

source ~/.bash_profile

You should then be able to use your local installation of PEAR on the command line:

$ which pear
/home/(yourusername)/pear/pear

Search, install, upgrade, and list PEAR packages

To search for a PEAR package:

$ pear search dba
Retrieving data...0%
.Matched packages, channel pear.php.net:
=======================================
Package Stable/(Latest) Local
DBA 1.1.1 (stable) 1.1.1 Berkely-style database abstraction class
DBA_Relational 0.2.0 (beta) Berkely-style database abstraction class

To install a PEAR package, simply run the following (where dba is the name of the package):

$ pear install --onlyreqdeps dba
downloading DBA-1.1.1.tgz ...
Starting to download DBA-1.1.1.tgz (13,144 bytes)
.....done: 13,144 bytes
install ok: channel://pear.php.net/DBA-1.1.1

To install a specific version of a PEAR package (it's typically best to just use the latest stable though which is the default):

$ pear install --onlyreqdeps dba-0.17
downloading DBA-0.17.tgz ...
Starting to download DBA-0.17.tgz (31,694 bytes)
.........done: 31,694 bytes
install ok: channel://pear.php.net/DBA-0.17

To upgrade a package:

$ pear upgrade dba
downloading DBA-1.1.1.tgz ...
Starting to download DBA-1.1.1.tgz (13,144 bytes)
.....done: 13,144 bytes
upgrade ok: channel://pear.php.net/DBA-1.1.1

To see a list of installed packages:

$ pear list
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.4.3 stable
Console_Getopt 1.4.1 stable
DBA 1.1.1 stable
PEAR 1.10.6 stable
Structures_Graph 1.1.1 stable
XML_Util 1.4.3 stable

Using your modules in your PHP scripts

To use the files you have installed, you should set your PHP include_path in the code that uses your PEAR packages like so:

set_include_path('~/pear/lib' . PATH_SEPARATOR
. get_include_path());

An example which then prints the phpinfo() page afterwards is:

$ cat peartest.php
set_include_path('~/pear/lib' . PATH_SEPARATOR
. get_include_path());
phpinfo();
?>