Steps to install PhpRedis & Redis Server in CentOS

What is Redis?

Redis is a flexible, open-source, key value data store. It’s other NoSQL databases, such as Cassandra and MongoDB. Redis allows the user to store vast amounts of data without the limits of a relational database.It is written in ANSI C. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. So here you will find the steps to install phpRedis and Redis server in CentOS server.

Redis consists of two key parts, first being the server it self and second PhpRedis extension that allows PHP to communicate with Redis.

The procedure should apply to Fedora and Red Hat distributions as well. In case you feel like skipping these steps, feel free to use the GitHub for an even simpler installation and configuration of Redis as a service

Redis can be install using Linux repository “yum” and from source. We will cover both type of installation.

Redis Install by “yum” Repository –

Follow these blow steps to install Redis & Redis-Server in Linux using yum repository which will automatically install and setup redis on server which is very fast and easy to setup.

First, install the epel repo

Next, install the remi repo

Now, you should be able to install redis using the yum package manager.

You should now be able to start redis using the following command

Install Redis Server in CentOS from Source

There is another way of installation of redis using source which is also suggested by redis community as redis has no dependency other than gcc compiler so it’s the best way to compile redis from source. As installation using package manager may sometime not installing latest version of redis in server.

First we have to download and install a compiler. This will help us install Redis from source:

Download and Compile Software

Begin the installation process by issuing the following sequence of commands to download the software and prepare it for use:

This will download and compile the 2.2.2 version of Redis.  It is important to use the most up to date version of the software to avoid security flaws and bugs as well as to take advantage of the latest features. When you compile software manually, you are responsible for ensuring your system is running the most current version without the assistance of your system’s package management tools.

Now we will modify the default configuration of the Redis and change the location of the database. We would also change the log notices to a production acceptable level and the location of the log file.

After executing above command your redis.conf file will look like as per below –


Add the ‘redis’ init script


Create a file and add below code for start service in init script


Give appropriate permission to the init script

To run the ‘redis’ server at startup we need to add it to the chkconfig list

Finally we are ready to start the Redis Server

Check if Redis is working

External programs talk to Redis using a TCP socket and a Redis specific protocol. Redis provide a command line utility which used to send command to redis on backend. This program is implemented in different language. This program is called redis-cli.

The first thing to do in order to check if Redis is working properly is sending a PING command using redis-cli:

If you get PONG in return that means redis server is working fine on server.

Another way to run redis-cli is without arguments: the program will start in interactive mode, where you can type different commands and see their replies.

Install Redis extension of PHP using Source

First we need to install “php5-dev” which  provides the dev library as well as the phpize command which is required for the compiling Source code.

Next we will download phpredis from git repository. Install Git if you don’t have using following command.

Compile and install phpRedis by running the following commands.

Next we need to add extension with php configuration so that php can enable this module using following command. This step need root access for updating php extension file.

To check Redis is working with php we make a simple php file as follow and run it.

And wirte the following code in the phpredis.php file.

Now, run the phpredis.php file either using your browser or command line i am here to chose command line option as.

If this file runs without any error then check cache with redis using following command.

if the above result found that means Redis is working perfectly. If not that means you have missed some steps from above.


‘Redis’ also supports datatypes such as Transitions, Publish and Subscribe. ‘Redis ’ is considered more powerful than ‘Memcache’ . It would be smart to bring ‘Redis’ into practice and put ‘Memcache’ down for a while.