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.
There are several options for downloading PECL extensions, such as:
Listed here is information like the ChangeLog, release information, requirements, revisions, etc. Although not every PECL extension has a webpage, most do.
pear download extname
The pear command may also be used to download source files. Specific revisions may also be specified.
CVS
All PECL files reside in CVS. A web-based view may be seen at http://cvs.php.net/pecl/. To download straight from CVS, consider the following where phpfi is the password for user cvsread:
$ cvs -d:pserver:cvsread@cvs.php.net:/repository login $ cvs -d:pserver:cvsread@cvs.php.net:/repository co pecl/extname |
Windows downloads
Windows users may find compiled PECL binaries by downloading the Collection of PECL modules from the PHP Downloads page, and by retrieving a PECL Snapshot. To compile PHP under Windows, read the Win32 Build README.
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.
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.
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.
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 |