Thursday 23 May 2013

Install PHP Extensions using PECL on RHEL/CentOS/Scientific Linux

Installing PHP extension is very easy, if you install using PECL, PHP Extension Community Library, a repository of PHP extensions that are made available to you via PEAR packaging system. To enable PECL

# yum install php-pear (which will give you pecl command)

I'm going to show you how to install the following PHP extensions.

1. phpredis
# pecl install redis
To load the extension on PHP startup, add "extension=redis.so" to /etc/php.ini
Restart web services (service httpd restart)
To verify this
# php -m | grep redis

2. MongoDB
# pecl install mongo
To load the extension on PHP startup, add a line: "extension=mongo.so" to /etc/php.ini
Restart web services (service httpd restart)

3. AMQP/RabbitMQ
Amqp requires these two packages installed: librabbitmq (RabbitMQ client itself) and librabbitmq-dev (dev headers etc.)
# yum install librabbit*
# pecl install amqp
Once the installation has completed we should add "extension=amqp.so" to /etc/php.ini
Restart web services (service httpd restart)

Issues: What if the desired extension is not available with PECL?
You need to install manually. The phpize command (you need to install php-devel to get this) is used to prepare the build environment for a PHP extension.

Download the tarball from the website using wget/curl, unpack using tar, read README/INSTALL, configure, build and install.

# wget/curl <link address>
# tar xvzf phpextnname.tar.gz or tar xvjf phpextnname.tar.bz2
# cd phpextnname
# phpize
# ./configure
# make
# make install

A successful install will have created extname.so and put it into the PHP extensions directory. You'll need to and adjust php.ini and add an extension=extname.so line before you can use the extension.
Restart web services (service httpd restart)
You can verify this by
# php -m | grep <php_extension_name>

Note: Don't delete your Makefile, if you want to uninstall your program at a later stage.
# make uninstall

2 comments: