RPM: how to build Redis library package for PHP

At Supportex we use Redis a lot. It’s extremely fast and doesn’t consume a lot of resources.  Besides it’s easy to use for developers (especially for those who worked with Memcache). Unlike Python which has only one mature client, PHP has various of them.  For instance, Predis, phpredis,  Rediska, etc. We prefer phpredis. It’s written in C and that is a better way to go. Now it is being developed  by Nicolas Favre-Felix.

If you use rpm-based system like Fedora or Centos you definitely should install it from rpm. Here is what you need to do.  I assume that you already have rpmbuild environment.

Download last version of library to SOURCES directory.

wget -O nicolasff-phpredis-2.1.3-20-g9e1d068.tar.gz https://github.com/nicolasff/phpredis/archives/master

Note that version nicolasff-phpredis-2.1.3-20-g9e1d068 was the last at the time of writing and you probably will need to change its name.

Download .spec file to SPECS directory:

wget -O php-redis.spec https://raw.github.com/nicolasff/phpredis/master/rpm/php-redis.spec

Change Source0 and setup lines to your tarball name:

Source0: nicolasff-phpredis-2.1.3-20-g9e1d068.tar.gz
%setup -q -n nicolasff-phpredis-9e1d068

Run rpmbuild:

rpmbuild -bb ~/rpmbuild/SPECS/redis-php.spec

If there are no errors, you will get RPM package:

[builder@playground ~]$ ls -l ~/rpmbuild/RPMS/x86_64/
-rw-rw-r-- 1 builder builder 224184 Aug 25 12:14 php-redis-2.1.3-1.fc15.x86_64.rpm
[builder@playground ~]$

Install it:

[root@playground ~]# rpm -ivh /home/builder/rpmbuild/RPMS/x86_64/php-redis-2.1.3-1.fc15.x86_64.rpm
Preparing... ########################################### [100%]
1:php-redis ########################################### [100%]
[root@playground ~]#

And use:

<?php $redis = new Redis(); 
$redis->
pconnect('127.0.0.1', 6379);
echo $redis->
ping(), "n"; 
?>
[web@playground ~]$ php -f redis.php
+PONG
[web@playground ~]$

Didn’t find the answer to your question? Ask it our administrators to reply we will publish on website.

Leave a Reply

Your email address will not be published. Required fields are marked *