PHP: Setup your Own PHP PEAR Environment
In this article, we will show you how to setup your own PEAR Environment for PHP.
1) Login to your account via SSH
2) Let us first ensure that we are not already running a custom environment for PEAR. We can do this by running the following command…
If the results are not “/usr/local/bin/pear” and they show a home directory, that means you are already running a custom environment for PEAR.
3) Once we have confirmed that we are not running a custom environment, we can start the process. The first thing we need to do is create the PEAR config file. We can do this by running the PEAR config file creator script using the following command…
pear config-create $HOME $HOME/.pearrc
This command will return a lot of information, you don’t need to worry about any of the results. What this file does, is create the “.pearrc” file to your home directory. Most people prefer to keep the PEAR files out of their home directory. We can do this by running the following command…
pear config-set bin_dir $HOME/bin
This will make it so that all PEAR binaries get installed to the folder we set at the end of the result ($HOME/bin). You should see a “config-set succeeded” at the end of the results confirming that the command ran without any issues.
4) We can now test our setup by trying to install a PEAR library. For this example, we will try installing XML_Parser by using the following command…
pear install XML_Parser
You should see something similar to “install ok: channel://pear.php.net/XML_Parser-1.3.4” towards the end of the results.
5) In order for PHP to use our new local PEAR environment, we need to let PHP know we have one. To do this, we need to edit/create a .user.ini file. If you already have a custom .user.ini file, open it with your preferred text editor. If you do not have a .user.ini file setup, please click here for information on how to create one, then open it to make the modification below (e.g. “nano ~/public_html/.user.ini”).
After you have opened your php.ini file, locate the following line…
include_path = ".:/usr/lib/php:/usr/local/lib/php"
Replace the line with the following…
include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/USERNAME/pear/php"
Note: Make sure you replace USERNAME with the actual username for your account!
If you did not run the 2nd command in step 3, or if you changed the path that PEAR uses in step 3, you will need to also make that change here.
Your account should now be all set to use PEAR. If you install any PEAR libraries that include binaries (symfony 1, for example), you may simply call them via the binary name as they will be installed in $HOME/bin.
Please remember that some PEAR libraries are not in the default PEAR channel and you must do a “pear channel-discover” on the third party channel in order for PEAR to find the requested library.
If you have any questions, please feel free to leave a comment below!