Book Image

The PEAR Installer Manifesto

By : Gregory Beaver
Book Image

The PEAR Installer Manifesto

By: Gregory Beaver

Overview of this book

PEAR stands for PHP Extension and Application Repository, and its primary purpose is to support code re-use. PEAR provides both an advanced installer and a code repository at PEAR code is organized into discrete re-usable components called packages. A package consists of a group of files and a descriptor file called package.xml that contains metadata about the package's contents, such as the package version, any special dependencies, and textual information such as the package description and authors. The software that transforms a package from an inert grouping of files into a dynamic software package is called the PEAR Installer and is itself a PEAR package. In other words, the PEAR Installer can be used to upgrade itself. It truly is a very powerful application. In short, the PEAR Installer is one of the most effective tools for managing a high-quality software library, high-quality applications, or high-quality websites. This book will show you a new way of organizing your PHP development, by leveraging the full power of the PEAR Installer. In a sense, the PEAR Installer is a step above a software design pattern, a meta-development pattern that can be used to systematically organize all of your PHP development. You will learn how to organize your code into packages using the package.xml format. You will learn about the revolutionary new PEAR Channel concept, and how to safely and reliably depend on external PHP libraries from sources such as and other PEAR channels. You will learn about the PEAR_PackageFileManager package, and how to customize individual installations of your PHP code through file roles, file tasks, and post-installation scripts. In addition, you will learn how to use the power of PEAR to manage your web projects with the PEAR installer to bring the power of versioning and rollbacks to your live website. The synergy of the PEAR Installer and a revision control system like CVS or Subversion is also explored in depth. Next, you will learn how to set up your own PEAR Channel for distributing PHP applications, both open-source and proprietary closed-source PHP applications that can be secured using technology already built into the PEAR Installer. Finally, you will learn how to embed the PEAR Installer inside your own web application in order to manage plug-ins from a remote server. The book covers in detail designing a custom plug-in system for a fictitious blog application. The plug-in system is used to manage templates, and the PEAR Installer is used to manage the details of querying the remote server for templates, handling dependencies between versioning, and doing the actual installation process as well.
Table of Contents (11 chapters)
The PEAR Installer Manifesto
About the Author
About the Reviewers


Chances are, you've seen the acronym PEAR at some point in your use of PHP, whether it was in passing or when installing and using a package from If you've investigated, you've probably heard of popular software provided by PEAR, such as the DB database abstraction package, or the HTML_QuickForm package. What you may not realize is that PEAR is much more than just a collection of packages that you can use. PEAR also contains the most versatile installation program for PHP, the PEAR installer.

With the PEAR installer, you can do much more than just install packages from You can install packages from other PEAR channels, distribute your own software projects using your own PEAR channel, and even maintain a complex web project, all using the PEAR installer. Surprised? Well read on, as this book reveals the intimate secrets of the PEAR installer and how it will revolutionize your everyday development with the PHP programming language!

What This Book Covers

Chapter 1 introduces you to the PEAR installer. We begin with a look at the traditional unzip-and-go method of distributing PHP software and compare its advantages and disadvantages to the PEAR installer's package-based method of distributing PHP software. You will see the innovation of PEAR channels, take a peek inside how the PEAR installer installs files from packages, and learn how it knows where to install them. Finally, you will see the many ways to acquire the PEAR installer and even how to install PEAR remotely onto a web host that does not provide shell access.

Chapter 2 is a must-read for all PHP developers, as it explains the basic workings of package.xml, the heart of the PEAR installer. package.xml is used to control almost everything the PEAR installer can do. You will learn about the importance of versioning in controlling the quality of packages installed, the importance of dependencies, and how the PEAR installer manages this important link between libraries and applications. You will also learn how package.xml organizes package metadata such as the package name, authors, release notes, and changelog, and has critical installation data such as files, dependencies, and versioning organized.

Chapter 3 goes further in depth for developers who want to take advantage of the full application-support features introduced in package.xml version 2.0.

Chapter 4 takes a break from looking at the details of the PEAR installer, and dives into using the PEAR installer to develop and to maintain a complicated and rapidly evolving website.

Chapter 5 covers PEAR channels. Channels are designed to make it easy to install packages from any location, but difficult to compromise your system in the process, following a basic security principle: always design things so that the easiest way to do them is the most secure.

Channels open up's monopoly over the PEAR installer to the entire Internet. Custom-built packages distributed through your channel can even be sold and made available to specific users while co-existing peacefully with publicly available open-source packages.

Chapter 6 teaches you how to embed the PEAR installer to create a plug-in manager. The chapter creates a fake blog application that provides the ability to seamlessly query a remote PEAR channel server designed to distribute templates. Using the internal classes of the PEAR installer, our blog web application intelligently installs and upgrades templates with all of the sophistication expected from the PEAR installer.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

There are three styles for code. Code words in text are shown as follows: "Next, you need to create a configuration file for the remote machine using the config-create command."

A block of code will be set as follows:

<file name="blah.php" role="php">
<tasks:replace from="@DATABASE-URL@" to="database_url"
type="pear-config" />

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:

if (is_object($infoplugin)) {
$bag = new serendipity_property_bag;
if ($bag->get('version') == $data['version']) {
$installable = false;
} elseif (version_compare($bag->get('version'),
$data['version'], '<')) {
$data['upgradable'] = true;

$data['upgrade_version'] = $data['version'];
$data['version'] = $bag->get('version');

Any command-line input and output is written as follows:

$ pear c pear.ini remote-install o DB_DataObject

New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "clicking the Next button moves you to the next screen".


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader Feedback

Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to , making sure to mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer Support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the Example Code for the Book

Visit, and select this book from the list of titles to download any example code or extra resources for this book. The files available for download will then be displayed.

The downloadable files contain instructions on how to use them.


Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting, selecting your book, clicking on the Submit Errata link, and entering the details of your errata. Once your errata have been verified, your submission will be accepted and the errata added to the list of existing errata. The existing errata can be viewed by selecting your title from


You can contact us at if you are having a problem with some aspect of the book, and we will do our best to address it.