How do I install PEAR on my Web Server

Warning: This article was published many years ago (greater than two) Oct 31, 2017. Some information may be outdated.

Installing PEAR on DreamHost

The following information walks you through the following:

  • How to set up your DreamHost environment to run PEAR. (its should work on other hosting like godaddy, etc with a few alterations)
  • How to download and install the packages.
Pre RequisiteInstall PEAREdit the .bash_profileSetup the Environmentfinal setup for PEAR
1. SSH Enabled on your server: learn more at DreamHost
2. Ensure you have imported the RSA Keys etc and have the proper setup on your OS for SSH to your hosting server: Learn more at DreamHost

Step 1: Log in to your Server using SSH

tsk_mbp> SSH user@dreamhostserver.com
[server]$

Step 2: Get the your root folder path

[server]$ pwd
/home/exampleuser

User is named ‘exampleuser’. which is actually your user setup directory.
In this example, you can see you’re in the users directory because the full path is /home/exampleuser.

Step 3: Run the following wget command to download the go-pear.phar file to your users directory:

[server]$ wget http://pear.php.net/go-pear.phar
--2015-01-26 10:27:03-- http://pear.php.net/go-pear.phar
Resolving pear.php.net (pear.php.net)... 5.77.39.20
Connecting to pear.php.net (pear.php.net)|5.77.39.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3673193 (3.5M) [application/octet-stream]
Saving to: `go-pear.phar'

100%[=====================>] 3,673,193 1.26M/s in 2.8s

2015-01-26 10:27:06 (1.26 MB/s) - `go-pear.phar' saved [3673193/3673193]

Step 4: Run the file by entering this command in the same directory:

 [server]$ /usr/local/php56/bin/php go-pear.phar 

The Installation will start, provide the following responses at the prompts:

 1-11, 'all' or Enter to continue:

click ENTER on your keyboard; The install will continue to run, but then stops at this question:

Would you like to alter php.ini ? [Y/n] :

Enter the letter ‘n’ and then click Enter to proceed with the install. again the script will stop

Currently used php.ini (guess) : /etc/php56/php.ini
Press Enter to continue:

Click Enter again on your keyboard. that its..

Step 5: add the following two line to .bash_profile

export PHP_PEAR_PHP_BIN=/usr/local/php56/bin/php
export PATH=${HOME}/pear/bin:/usr/local/php56/bin:${PATH}
[server]$ nano ~/.bash_profile
# ~/.bash_profile: executed by bash(1) for login shells.

umask 002
PS1='[\h]$ '
export PHP_PEAR_PHP_BIN=/usr/local/php56/bin/php
export PATH=${HOME}/pear/bin:/usr/local/php56/bin:${PATH}

Enter Cntrl+X and then Y and ENTER for the prompts

Step 6: Run the following command to allow your current Shell session to use PEAR

[server]$ . ~/.bash_profile

Step 7: to use PEAR Edit the “phprc: file

Make sure you’re in your users directory by typing in ‘pwd’ to confirm:

[server]$ cd ~
[server]$ PWD
/home/exampleuser

Step 8: make dir for the php version, i am making two one for PHP7 and other for PHP5.6

[server]$ mkdir -p ~/.php/7.0
[server]$ mkdir -p ~/.php/5.6

Step 9: repeat the following in both directory,

If the user has three domains on your webserver, where two are running PHP 7.0 and the third is running PHP 5.6, only the first two domains running 7.0 would be affected by the phprc file. You would need to create a separate phprc file for the PHP 5.6 site.

[server]$ cd .php/7.0
[server]$ pwd
/home/exampleuser/.php/7.0
[server]$ nano phprc
add the following line to the phprc file
include_path = ".:/home/username/pear/share/pear"

for php5.6

[server]$ cd .php/5.6
[server]$ pwd
/home/exampleuser/.php/5.6
[server]$ nano phprc
add the following line to the phprc file
include_path = ".:/home/username/pear/share/pear"

Note: ensure the “username” in /home/username/pear/share/pear is your path name.

When you install pear, it uses the server’s /tmp directory. On a shared server, this may cause the installation of packages to fail. Hence let’s change the paths

Step 10: Check if the installation is working

[server]$ cd ~
[server]$ pear list

Installed packages, channel pear.php.net:
Package Version State
Archive_Tar 1.3.12 stable
Console_Getopt 1.3.1 stable
PEAR 1.9.5 stable
Structures_Graph 1.0.4 stable
XML_Util 1.2.3 stable

Since you receive a response, you can see that PEAR is now functioning.

Step 11: adjust three configuration options in your pear config

[server]$ cd ~
[server]$ mkdir tmp
[server]$ pear config-set cache_dir /home/username/tmp
config-set succeeded
[server]$ pear config-set download_dir /home/username/tmp
config-set succeeded
[server]$ pear config-set temp_dir /home/username/tmp
config-set succeeded

Note: ensure the “username” in /home/username/tmp is your path name.

Step 12: Check everything is working

[server]$ pear install --onlyreqdeps Mail

The PHP Extension and Application Repository, or “PEAR”

The PHP Extension and Application Repository, or “PEAR”, is a repository of reusable PHP code which you can add to your website to easily enable certain functions such as SMTP Mail.

Various packages can be downloaded from the PEAR repository, at: http://pear.php.net/packages.php

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.