Team LiB
Previous Section Next Section

Installing PEAR

Finally, we show you how to install PEAR, the PHP Extension and Application Repository. Its home page is It is a collection of PHP extensions, either written completely in PHP or written in C (the latter is called PECL: PHP Extension Community Library). For instance, the tidy class covered in Chapter 16, "Working with HTML/XHTML Using Tidy," is a PECL extension.

Formerly, PEAR was a mess on Windows. The installation did not really work. In the meantime, the situation has become much betterusing PEAR is now easy. As a part of the PHP package, a script called go-pear is copied to your system; alternatively, you can download such a script from the Web. Unix/Linux users may use lynx to get the file:

$ lynx -source > go-pear.php

Windows users have to load into their Web browser and then save the results.

Next, run the downloaded script:

$ php go-pear.php

Now, even though it's a console application, you are guided through the installation (see Figure A.9) and have to provide the installation path and other PHP-related settings. However, most of the time the installer does a good job of guessing the correct values.

Figure A.9. Installing PEAR using the command-line interface.

After that, a script pear is created, which you can also call from the command line. The following command installs a package:

$ pear install Net_DIME

If this package has not issued a stable version yet, you will have to provide the exact version of the package you want to install; in the case of Net_DIME, this would look like this:

$ pear install Net_DIME-0.3

Upgrading a package can be done in the following way:

$ pear upgrade Net_DIME

If you want to get a list of all available packages, run

$ pear list

The following command removes the package from the system:

$ pear uninstall Net_DIME

One of the most famous packages of PEAR is PEAR::SOAP, the package that allows the use of Web services. This package, however, depends on four other packages, so you have to run several commands to get all the required packages and get PEAR::SOAP to run (at time of press, some of this package was still in beta stage, so you would have to provide the exact version number; check with the PEAR website to see which versions are the most current ones):

$ pear install Net_DIME
$ pear install Net_Url
$ pear install HTTP_Request
$ pear install Mail_Mime
$ pear install SOAP

PECL packages, that are PHP extensions written in C but not part of the PHP core distribution, are also part of PEAR and available at Under Unix/Linux, you can install PECL packages like you would install PEAR packages: pear install packagename. The installer downloads the sources and compiles them; sometimes, you still have to load the .so file using a php.ini directive. Also, some of those extensions require additional libraries to available. The main author's Tidy extension depends on libtidy, available at After installing the library, pear install tidy does the trick. Or, you configure PHP with the --with-tidy switch.

Windows users do not have the compilation option. However, the PHP 5 download page offers a special package containing precompiled binaries of many PECL extensions, including Tidy. So you can get the DLL files there, copy them into PHP's ext directory and then load them using extension=filename.dll in php.ini. Most extensions not included there are compiled on a regular basis and may be downloaded from

As this appendix has shown, installing PHP and associated modules and extensions is easy most of the time, and especially, it's easier than it has been before. Also, the PHP online manual's user annotations and the PHP newsgroups offer further information, tips, and support.

    Team LiB
    Previous Section Next Section