Installing PEAR
May 10th, 2006
PEAR, the PHP Extension and Application Repository, has been around since 1999, and has several functions. According to the 'About PEAR' page:
The purpose of PEAR is to provide:
- A structured library of open-sourced code for PHP users
- A system for code distribution and package maintenance
- A standard style for code written in PHP
- The PHP Extension Community Library (PECL)
- A web site, mailing lists and download mirrors to support the PHP/PEAR community
Getting Started
For most PHP coders, including myself at one point, PEAR seemed to be a bit of a mystery for those who shy away from object orientated programming. The first point to remember is this: you don't need OOP knowledge to use PEAR! Yup, no lies, you can use it if you have an ounce of intelligence, and can read the documentation! So, to calm the fear of PEAR, I'm going to take a step by step approach to installation, and the usage of several PEAR classes in a series of posts.
By default, PEAR is installed along with PHP and if you have shell access, installation of classes is a breeze. However, if you are on a shared host (as most people are!) you will need to install a local copy of PEAR. There are installation instructions available on the PEAR website, however, these can be a bit confusing. So here's what I've done:
Installing PEAR
- Download the latest version of PEAR. At the moment, the current version is 1.4.9.
- Unpack the downloaded files. You will then get a folder called PEAR-1.4.9 which should contain a few folders and some scripts, one being called PEAR.php. Upload all these files and folders to a non web-accessible folder called 'pear' on your web server. For me, this is /home/user/pear/.
- You now need to add this to your include path. This can be done easily with a .htaccess file. The folders you will need to have included are:
- . - The current working directory that the script is running in
- /home/user/pear/ - The directory where we just installed pear
You can place these directories in a .htaccess, separating then with a colon:
php_flag include_path .:/home/user/pear - You can check your PEAR installation works by creating a test php file:
If you get an output similar to the below, then you are on your way to using PEAR!
PEAR Object ( [_debug] => [_default_error_mode] => [_default_error_options] => [_default_error_handler] => [_error_class] => PEAR_Error [_expected_errors] => Array ( ) )
Loading the Packages
Loading PEAR packages can be done in two ways. If you have ssh/shell access to your web server, its as simple as using pear install <package>. For example: pear install Calendar will install the Calendar package.
If you don't have shell access and you have installed PEAR using the instructions above, then its a matter of downloading the packages, and placing them in your /home/user/pear/ directory.
- Download the Calendar package
- Unpack the file, and you'll get a folder named Calendar-0.x.x with various PHP files and folders inside.
- Upload this folder to your /home/user/pear/ directory and you are all set!
To use the package, its as simple as this:
You can read up on the Calendar package here.
Using PEAR can be a time saver, and its worth taking a look around the package list to see what is available for use. It does take a bit of work initially to get used to using the classes if you haven't before, but after that, its a complete life saver!
Add to del.icio.us
Digg this
Technorati
Related Posts:
- PHP, Mime Types and Fileinfo
- Oracle XE and libaio
- Installing PECL Modules
- Running Oracle 10g XE & PHP on Linux
Entry Filed under: PEAR
1 Comment Add your own
1. George Ngoru | February 6th, 2007 at 12:52 pm
Hello!. Thanx. Finall mange to install PEAR with out problems
But i would like some help on the networking packages.
The DNS resolver is properly excecuted in www root but there is no output in the page….
and there is NO error message
I also copies the example code exactly…
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed