Setup PEAR and install PEAR packages

in Tools

As PEAR is not installed by default to make use of it, you’ll need to install it manually.
These steps describe how to install PEAR in your own home directory.

  • Get the PEAR installer:
wget -O /tmp/go-pear.phar # Get the installer 
  • Run the installer:
cd /data/web/
php /tmp/go-pear.phar
  • Adjust settings prior to installing PEAR:

The installer will notice your are running the install as non root, therefore adjusting it’s path. If it doesn’t, please use this configuration:

1. Installation base ($prefix)                   : /data/web/pear
2. Temporary directory for processing            : /tmp/pear/install
3. Temporary directory for downloads             : /tmp/pear/install
4. Binaries directory                            : /data/web/pear/bin
5. PHP code directory ($php_dir)                 : /data/web/pear/share/pear
6. Documentation directory                       : /data/web/pear/docs
7. Data directory                                : /data/web/pear/data
8. User-modifiable configuration files directory : /data/web/pear/cfg
9. Public Web Files directory                    : /data/web/pear/www
10. Tests directory                              : /data/web/pear/tests
11. Name of configuration file                   : /data/web/.pearrc

When this output is printed to the screen, type enter to continue or type ‘all’ to set the locations by yourself.

When the PEAR installer asks to alter the php.ini choose: NO

After running the installer, PEAR is installed and you can run it on the command line using /data/web/pear/bin/pear,

Configuring PEAR

To configure PEAR, we generate a .pearrc config file:

/data/web/pear/bin/pear config-create ~/ .pearrc

This will create a .pearrc in your homedir (/data/web/.pearrc)

Use PEAR on the cli

To make our life easy, let’s add the pear/bin to our path, so we don’t have to type the absolute path to run PEAR:

echo 'PATH="/data/web/pear/bin:${PATH}"' >> ~/.bashrc 

Now logout and log back into your hypernode, and you can run PEAR command by just typing pear instead of /data/web/pear/bin/pear

Use PEAR in php

System.php is shipped with every PEAR installation and thus should be on your hypernode too. Therefore we’ll use it to test whether PEAR is working.
To use it, we must add our PEAR lib directory to the php include path, so php is able to find the libraries.

  • Create a script in /data/web/public/peartest.php with the following content:
    ini_set('display_errors', 1);
    ini_set('include_path', '/data/web/pear/share/pear' . PATH_SEPARATOR . ini_get('include_path'));
    require_once 'System.php';

Now if you run the script on the commandline or through your browser, a boolean should be returned, returning True when OK

  • Installing PEAR packages

Install a package by running:

pear install pear/Net_GeoIP

Which should give you the following output:

downloading Net_GeoIP-1.0.0.tgz ...
Starting to download Net_GeoIP-1.0.0.tgz (542,008 bytes)
.............................................................................................................done: 542,008 bytes
install ok: channel://
  • Adjust php include_path to use PEAR in your shop

To use PEAR packages in your application, you should adjust the include path in your php script:

   ini_set('include_path', '/data/web/pear/php' . PATH_SEPARATOR . ini_get('include_path'));