Recipe 26.7. Installing PECL Packages

26.7.1. Problem

You want to install a PECL package; this builds a PHP extension written in C to use inside PHP.

26.7.2. Solution

Make sure you have all the necessary extension libraries and then use the PEAR installer bundled command pecl:

% pecl install mailparse

To use the extension from PHP, add the appropriate line to your php.ini file:

26.7.3. Discussion

The frontend process for installing PECL packages is just like installing PEAR packages for code written in PHP. However, the behind-the-scenes tasks are very different. Because PECL extensions are written in C, the installer needs to compile the extension and configure it to work with the installed version of PHP. As a result, at present, you can build PECL packages on Unix machines if you have the necessary development tools installed and on Windows machines if you use MSDev.

Unlike PHP-based PEAR packages, PECL extensions don't automatically inform you when you lack a library necessary to compile the extension. Instead, you are responsible for correctly preinstalling these files. If you are having trouble getting a PECL extension to build, check the README file and the other documentation that comes with the package. The installer puts these files inside the docs directory under your PEAR hierarchy.

When you install a PECL extension, the pecl command downloads the distribution file, extracts it, runs phpize to configure the extension for the version of PHP installed on the machine, and then makes and installs the extension. It may also prompt you for the location of libraries:

% pecl install mailparse downloading mailparse-2.1.1.tgz ... Starting to download mailparse-2.1.1.tgz (35,883 bytes) ..........done: 35,883 bytes 9 source files, building running: phpize Configuring for: PHP Api Version:         20031224 Zend Module Api No:      20041030 Zend Extension Api No:   220040412 ... Build complete. (It is safe to ignore warnings about tempnam and tmpnam). running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-mailparse-2.1.1" install Installing shared extensions: /var/tmp/pear-build-root/install-mailparse-2.1.1/usr/lib/php/20041030/ running: find "/var/tmp/pear-build-root/install-mailparse-2.1.1" -ls 8306920    4 drwxr-xr-x   3 root     root      4096 May  1 16:40 /var/tmp/pear-build-root

install-mailparse-2.1.1 4522201 4 drwxr-xr-x 3 root root 4096 May 1 16:40 /var/tmp/pear-build-root

install-mailparse-2.1.1/usr 4522202 4 drwxr-xr-x 3 root root 4096 May 1 16:40 /var/tmp/pear-build-root

install-mailparse-2.1.1/usr/lib 4522203 4 drwxr-xr-x 3 root root 4096 May 1 16:40 /var/tmp/pear-build-root

install-mailparse-2.1.1/usr/lib/php 8306938 4 drwxr-xr-x 2 root root 4096 May 1 16:40 /var/tmp/pear-build-root

install-mailparse-2.1.1/usr/lib/php/20041030 8306939 140 -rwxr-xr-x 1 root root 136671 May 1 16:40 /var/tmp/pear-build-root

install-mailparse-2.1.1/usr/lib/php/20041030/ Build process completed successfully Installing '/var/tmp/pear-build-root/install-mailparse-2.1.1//usr/lib/php/20041030/' install ok: channel:// You should add "" to php.ini

PECL extensions are stored in different places than PEAR packages written in PHP. If you want to run pecl, you must be able to write inside the PHP extensions directory. Because of this, you may want to install these packages while running as the same user you used to install PHP. Also, check the execute permissions of these files; because most PEAR files aren't executable, your umask may not provide those executable files with the correct set of permissions.

If you're running PHP and PECL in a Windows environment, you may prefer to download precompiled DLLs for the PECL extensions you need from

PHP's dl( ) can be used to load extensions at runtime, but it is deprecated. If possible, activate new extensions in the php.ini file.

26.7.4. See Also

13.12 for information on installing PEAR packages; Recipe 26.5 for more on upgrading an existing package; Recipe 26.6 to uninstall a package; the PECL Windows Repository at .

PHP Cookbook, 2nd Edition
PHP Cookbook: Solutions and Examples for PHP Programmers
ISBN: 0596101015
EAN: 2147483647
Year: 2006
Pages: 445

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: