Home > php, phpredis, redis > Install phpredis on Ubuntu

Install phpredis on Ubuntu

Tested on Ubuntu 10.10 64bit server edition but should apply to other versions as well.

1) Preparation

sudo apt-get install php5-dev

php5-dev provides the dev library as well as the phpize command which is required for the compiling step
2) Get phpredis source code, should be pretty easy by running

git clone git://github.com/nicolasff/phpredis.git

3) Compile and install

cd phpredis
sudo -s make install

4) Enable the phpredis extension

sudo -s
echo "extension=redis.so">/etc/php5/conf.d/redis.ini

5) Write a simple php script to test (running on cli would be fine if php5-cli is installed)

        // phpredis_set.php
        $redis=new Redis() or die("Can'f load redis module.");
        $redis->set('set_testkey', 1);

Prior to try phpredis I was using Rediska as the php redis client. I did some pretty quick and dirty benchmarking comparison and phpredis is clearly a winner here, not surprisingly because phpredis is a compiled extension written in C while Rediska is a pure php library.

time for i in `seq 1 1000`; do php phpredis_set.php; done

real 0m13.072s
user 0m6.560s
sys 0m3.620s

time for i in `seq 1 1000`; do php rediska_set.php; done

real 0m21.035s
user 0m12.150s
sys 0m5.050s

and the source code for rediska_set.php:

        require_once 'Rediska/library/Rediska.php';
        $rediska=new Rediska();
        $rediska->set('set_testkey', 1);

The above tests were conducted on a single-core i3 2.1GHZ Virtualbox guest with 512MB of RAM.

Categories: php, phpredis, redis
  1. snakefast
    September 6, 2012 at 2:28 pm

    Thanks, this was useful to me.

  2. Mahesh
    February 1, 2013 at 7:03 am

    Thanks a lot Rico! You nailed it for me

    • February 1, 2013 at 10:10 pm

      No problem. Glad it helps.

  3. February 20, 2013 at 6:16 pm

    Great guide, great to see the comparison of the two! One note, I had to copy the compiled module to my PHP modules directory to get it working (Ubuntu 12.04). Cheers!

    • February 20, 2013 at 6:23 pm

      Hrmmm, must be an issue with that server, other server copied it over fine. Still a great guide, cheers!

  4. Raffaello
    May 14, 2013 at 12:06 am

    Thanks, it worked like a charm!

  5. Zsolt Szilagyi
    May 30, 2013 at 5:57 pm

    You can check successfull installation in one line:
    php -r “var_dump(get_class_methods(Redis));”
    shall print a list of availible methods.

    • May 31, 2013 at 11:43 am

      That’s clever! Thanks for sharing.

  6. June 3, 2015 at 6:39 pm


  1. July 23, 2012 at 7:35 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: