14 August 2009

Installing PHP extensions with pecl on Debian

'pecl' downloads packages from a repository for PHP apps or libraries, and installs them somehow as PHP packages. Or something. I don't really know what this does or means but as a sysadmin, our developers need this done occasionally.

So, in today's example, we need the GPG extension for PHP so that we can encrypt files using PHP.

shell# php -m
## big list of php extensions, and it seems we do not have GnuPG installed.



shell# pecl install gnupg
WARNING: channel "pecl.php.net" has updated its protocols, use "channel-update pecl.php.net" to update
downloading gnupg-1.3.1.tgz ...
Starting to download gnupg-1.3.1.tgz (19,331 bytes)
......done: 19,331 bytes
5 source files, building
running: phpize
sh: phpize: command not found
ERROR: `phpize' failed

shell# pecl install phpize
No releases available for package "pecl.php.net/phpize"
Cannot initialize 'channel://pecl.php.net/phpize', invalid or missing package file
Package "channel://pecl.php.net/phpize" is not valid
install failed


Lets first get the channel info correct:

shell# pecl channel-update pecl.php.net

Updating channel "pecl.php.net"

Update of Channel "pecl.php.net" succeeded



So now we need 'phpize' installed:

shell# aptitude install php5-dev
...
The following NEW packages will be installed:

autoconf automake automake1.4 autotools-dev libtool php5-dev shtool
...

shell# pecl install gnupg
WARNING: channel "pecl.php.net" has updated its protocols, use "channel-update pecl.php.net" to update
downloading gnupg-1.3.1.tgz ...
...
...
checking if nawk is broken... no
checking for gnupg support... yes, shared
checking for gnupg files in default path... not found
configure: error: Please reinstall the gpgme distribution
ERROR: `/tmp/pear/temp/gnupg/configure' failed



Now we need the development packages for gpgme according to that last error message:

shell# aptitude search gpgme
p libgpgme-ruby - GPGME bindings for the Ruby language
p libgpgme-ruby1.8 - GPGME bindings for the Ruby language
p libgpgme-ruby1.9 - GPGME bindings for the Ruby language
p libgpgme11 - GPGME - GnuPG Made Easy
p libgpgme11-dev - GPGME - GnuPG Made Easy

shell# aptitude install libgpgme11 libgpgme11-dev
...
The following NEW packages will be automatically installed:
libgpg-error-dev libpth-dev libpth20
...

shell#


Now, one last time:

shell# pecl install gnupg
downloading gnupg-1.3.1.tgz ...
Starting to download gnupg-1.3.1.tgz (19,331 bytes)
......done: 19,331 bytes
5 source files, building
running: phpize
...
...
Build process completed successfully
Installing '/usr/lib/php5/20060613+lfs/gnupg.so'
install ok: channel://pecl.php.net/gnupg-1.3.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=gnupg.so" to php.ini

shell#


As the instructions state again, make sure to edit your php.ini file to add
extension=gnupg.so
into that file's extensions area.

Easy huh? Well, if you know what you're looking for it can be.