Chapter 7. Installation of PECL extensions

Table of Contents
Introduction to PECL Installations
Downloading PECL extensions
PECL for Windows users
Compiling shared PECL extensions with PEAR
Compiling shared PECL extensions with phpize
Compiling PECL extensions statically into PHP

Introduction to PECL Installations

PHP extensions may be installed in a variety of ways. PECL is a repository of PHP extensions living within the PEAR structure, and the following demonstrates how to install these extensions.

These instructions assume /your/phpsrcdir/ is the path to the PHP source, and extname is the name of the PECL extension. Adjust accordingly. These instructions also assume a familiarity with the pear command.

Shared extensions may be installed by including them inside of php.ini using the extension PHP directive. See also the extensions_dir directive, and dl(). The installation methods described below do not automatically configure PHP to include these extensions, this step must be done manually.

When building PHP modules, it's important to have the appropriate versions of the required tools (autoconf, automake, libtool, etc.) See the Anonymous CVS Instructions for details on the required tools, and required versions.

Downloading PECL extensions

There are several options for downloading PECL extensions, such as:

PECL for Windows users

Like with any other PHP extension DLL, to install move the PECL extension DLLs into the extension_dir folder and include them within php.ini. For example:

extension=php_extname.dll

After doing this, restart the web server.

Compiling shared PECL extensions with PEAR

PEAR makes it easy to create shared PHP extensions. Using the pear command, do the following:

$ pear install extname

That will download the source for extname, and compile it on the system. This results in an extname.so file that may then be included in php.ini

In case the systems preferred_state is set higher than an available extname version, like it's set to stable and the extension is still in beta, either alter the preferred_state via pear config-set or specify a specific version of the PECL extension. For example:

$ pear install extname-0.1.1

Regardless, pear will copy this extname.so into the extensions directory. Adjust php.ini accordingly.

Compiling shared PECL extensions with phpize

If using pear is not an option, like for building shared PECL extensions from CVS, or for unreleased PECL packages, then creating a shared extension may also be done by manually using the phpize command. The pear command essentially does this but it may also be done manually. Assuming the source file is named extname.tgz, and that it was downloaded into the current directory, consider the following:

$ pear download extname
$ gzip -d < extname.tgz | tar -xvf -
$ cd extname
$ phpize
$ ./configure && make

Upon success, this will create extname.so and put it into the modules/ and/or .libs/ directory within the extname/ source. Move this shared extension (extname.so) into the PHP extensions directory, and adjust php.ini accordingly.

Compiling PECL extensions statically into PHP

To statically include the extension within the PHP build, put the extensions source into the ext/ directory found in the PHP source. For example:

$ cd /your/phpsrcdir/ext
$ pear download extname
$ gzip -d < extname.tgz | tar -xvf -
$ mv extname-x.x.x extname
$ rm package.xml

This will result in the following directory:

/your/phpsrcdir/ext/extname

From here, build PHP as normal:

$ cd /your/phpsrcdir 
$ ./buildconf
$ ./configure --help
$ ./configure --with-extname --enable-someotherext --with-foobar
$ make
$ make install

Whether --enable-extname or --with-extname is used depends on the extension. Typically an extension that does not require external libraries uses --enable. To be sure, run the following after buildconf:

$ ./configure --help | grep extname