Using PEAR

Dec 07, 2009 Author: City Hall

In the following sections you will learn how to use PEAR to find and install packages on a system, and you'll learn how to submit your own projects for consideration as PEAR packages.

Finding a PEAR Package

On every page of the PEAR website is a search box that you can use to search the package database. You simply enter a name, or part of a name, and all matching packages are displayed.


Searching Packages To perform a detailed search on a package name, maintainer, or release date, you can use the form at http://pear.php.net/package-search.php.


You can click the name of the package you are interested in from the search results. The page that is then displayed should give some key information about that package, including a summary of its features, the current release version, and status and information about its dependenciesthat is, any other PEAR packages that are required for this package to work.

The tabs at the top of the package details page allow you to view the documentation. If you are unsure from the summary information about exactly what you can achieve by using a particular package, you can browse through the documentation pages.

If you simply want to browse all the available PEAR packages, you can go to the categorized list at http://pear.php.net/packages.php.

Using the PEAR Installer

When you have decided that a package will be useful, you can download it from the web by using the tab at the top of its package information page. However, using the PEAR installer program is a quick and easy way to manage packages within a PHP installation. The installer is able to find and download the latest version of a package and can also install it for you automatically.

The PEAR installer is named pear. To run the installer, you run the pear command followed by a command option. To see all the packages currently installed on a system, you can use the list command option:

$ pear list


Command Options Running pear with no arguments brings up a list of all the available command options.


The output produced should be similar to the following:

Installed packages:
===================
Package Version State
DB 1.6.2 stable
HTTP 1.2.2 stable
Net_DNS 1.00b2 beta
Net_SMTP 1.2.6 stable
Net_Socket 1.0.1 stable
PEAR 1.3.2 stable
SQLite 1.0.2 stable

Each package name, the version installed, and its release status are shown. The actual packages installed on your system may differ from the ones shown here.

You can use the search command option to search the PEAR package database. To search for all packages that contain the string mail, you run the following command:

# pear search mail

The output produced displays all matching packages, their latest version numbers, and a brief summary. The search performed is not case-sensitive.

To view all the available stable PEAR packages, you use the list-all command:

# pear list-all

This produces a long list!

To download and install a package, you use the install command option followed by the name of the package. To install the Mail package, you issue the following command:

# pear install Mail_Queue

Some packages cannot be installed unless others are already installed on your system, and installation will fail if the required packages are not found. The following output shows an attempt to install the Mail_Queue package before the Mail package has been installed:

# pear install Mail_Queue
downloading Mail_Queue-1.1.3.tar ...
Starting to download Mail_Queue-1.1.3.tar (-1 bytes)
.....done: 98,816 bytes
requires package `Mail'
Mail_Queue: Dependencies failed

Some dependencies are optional. When you install the Mail package to fix the dependency reported in the previous error message, PEAR advises you that the functionality of the Mail package can be enhanced if you also install Net_SMTP:

# pear install Mail
downloading Mail-1.1.4.tar ...
Starting to download Mail-1.1.4.tar (-1 bytes)
.....done: 73,728 bytes
Optional dependencies:
package `Net_SMTP' version >= 1.1.0 is recommended to
utilize some features.
install ok: Mail 1.1.4

You can use the upgrade command option to download and install a later version of an installed package. To check whether a new version of the Mail package is released, you use the following command:

# pear upgrade Mail

If a later version than the one installed is found, it is upgraded automatically.


Upgrading Packages You can use the upgrade-all command to check for newer versions of all your installed PEAR packages at once.


If you want to remove a PEAR package completely, you use the uninstall command.

Contributing Your Own PEAR Project

If you have written a PHP project that you think will be useful to other developers, you might consider submitting a proposal to have it included in PEAR.

The online documentation (at http://pear.php.net/manual/en/guide-newmaint.php) includes a guide for project maintainers that details the process of first making sure that your project is suitable for submission to PEAR and then ensuring that your code is of a suitable standard. You should read that guide if you intend to write a package suitable for use by other developers. Even if your project is not suitable for PEAR, these guidelines will make you think about your software design and coding standards and will help you produce a much higher-quality package.


views 4187
  1. Add New Comment