Featured

How to Install the PHP Extension Library PEAR

PEAR is the PHP extension library. PEAR contains all the extensions that are written in PHP.

 

Its sister library is PECL, with extensions written in C. You integrate these extensions written in C either via php.ini (Windows) or via the configuration (Linux). PEAR, on the other hand, can be installed either via the script supplied with the installation or via a command prompt.

 

As PEAR is an official PHP project, we would like to close the circle at this point and describe the installation here in this blog post. However, it should be noted that the further development of PEAR is progressing very slowly (the installation fails under PHP 8.3, which is why the steps ahead will use PHP 8.2), and that the Composer and its package directory, Packagist, are setting the tone.

 

Install PEAR

Under Linux, PEAR is already installed. However, you could prevent this with the --without-pear directive during configuration.

 

Under Windows, you must install PEAR with the go-pear.phar file, which you can download from http://pear.php.net/go-pear.phar. In the following steps, we assume that you have saved this file in the C:\php directory:

  1. Switch to the command prompt.
  2. Go to the PHP folder there—for example, like this:

cd C:\php

  1. Execute go-pear.phar. PHAR here stands for PHP Archive and is essentially a file archive that contains PHP code for unpacking at the beginning:

php go-pear.phar

  1. You can install PEAR system-wide or locally (see the figure below; the warning messages do not bode well for future PHP versions). Local here means with relative paths—for example, for transport on a mobile hard disk.

Installing PEAR via the Console (Warnings Included)

  1. Then confirm the corresponding installation paths. They are written to the pear.ini file. On our test systems, we first had to specify the PHP folder (C:\php) under point 13 and set a storage location with write permissions for the pear.ini configuration file under point 12. Then the installation can start.

You must change the PATH Windows environment variable yourself if you want the pear command in the command prompt to be available outside the PHP directory—for example, C:\php.

 

The Installation Is Successfully Completed

 

To install new packages, use the pear command in the command prompt/console. Enter the command without options to see all possible entries. If you want to try it out right away, simply install a package. To do this, go to the command prompt and then to the PHP directory—for example, C:\php. Then enter the following line:

 

pear install XML_SVG

 

This installs the XML_SVG PEAR package.

 

The Installation Goes Smoothly

 

The PEAR command is quite powerful. Simply type it into the command prompt without any additions. You will then receive a list of all the options. We would like to briefly introduce some of them here:

  • The PEAR installation uses so-called channels via which the content is delivered. Use pear channel-update pear.php.net to retrieve the current PEAR channel after installation. Via the channels, other libraries can also use the PEAR installer.
  • If you want to install a PEAR package that does not yet have the status Final, you can specify the status as a switch. The most common switches are -alpha and -beta.
  • With the --alldeps switch (see the below figure), you can download all dependent packages. onlyreqdeps only downloads necessary packages.
  • pear install --alldeps HTML_CSS 

Dependent Packages Are Also Installed, with Some Warnings for (Still) Not Stable or Outdated Packages

  • You can also use the PEAR commands to update existing packages and search for specific packages. Simply enter pear in the command prompt, followed by upgrade package name. To search, use pear search and then the search term.

Note: There was once a second incarnation of PEAR, called PEAR2. This relied on a new PEARinstaller called Pyrus. However, work on this has now been completely discontinued, and the homepage has been shut down.

 

PEAR Packages without Installation

The PEAR packages are PHP files and therefore do not necessarily require installation. You can also place the corresponding packages directly in a directory on the web server and simply include them with require_once "path/package". The necessary steps can be found in the PEAR manual (http://s-prs.co/v602209).

 

Note: At http://s-prs.co/v602209, you will find tricks for installing PEAR at the host via Telnet/ SSH or FTP. However, the setup sometimes does not work depending on the security settings of the host.

 

You should now have a functioning PHP system available.

 

Editor’s note: This post has been adapted from a section of the book PHP and MySQL: The Comprehensive Guide by Christian Wenz and Tobias Hauser. Christian is a consultant and trainer who specializes in web technologies and web security. He leads digitization projects in corporate environments. His books have been translated into more than a dozen languages. Tobias is a consultant, trainer, and author. He supports companies with his focus on PHP-based web applications, covering everything from system selection to interface architecture, and writes regularly about web topics.

 

This post was originally published 4/2025.

Recommendation

PHP and MySQL
PHP and MySQL

Dive into web development with this comprehensive guide to PHP 8! Whether you’re a beginner or an experienced developer, you’ll find everything you need to build dynamic, secure websites. Walk through installing PHP, object-oriented programming, and working with databases like MySQL. Gain hands-on experience with detailed code and application examples. Master advanced topics like debugging, automated testing, security, and more!

Learn More
Rheinwerk Computing
by Rheinwerk Computing

Rheinwerk Computing is an imprint of Rheinwerk Publishing and publishes books by leading experts in the fields of programming, administration, security, analytics, and more.

Comments