How to Install Redis cache server in centos 7.

Date Posted: 02 -09-2018

Redis is an in-memory data structure store, used as a database server, cache, and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps and streams.

It also provides PHP module for communication between PHP script with Redis server. Redis is Written in C programming language.

In this tutorial will help you with the installation of Redis server along with PHP Redis PHP extensions on a CentOS 7 server.Let us have a step by step instructions, how to implement it.

Step 1 : Prerequisites

1. Login to your server using secured shell access with the root account.

# ssh root@remote

2. Redis packages are not available in our default Yum Repository, so that Install a EPEL  Reposistory on your server . To Enable this Repository, execute the following command shown below,

[root@sms ~]# sudo yum install epel-release

Package epel-release-7-11.noarch already installed and latest version. This will be a end output message conveyed to you.

Step  2 : Install Redis Server

1. Now, we can utilize a Yum repository , to install a Redis on our server.

[root@sms ~]# sudo yum install redis

2. After a  successful installation.start Redis service and enable to auto-start on system reboot.

[root@sms ~]# sudo systemctl start redis

Enable it and check,whether the Redis service is active in our server.

[root@sms ~]# sudo systemctl enable redis

 Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

Step 3 : Install Redis PHP extension

1.  Check  PHP  is  installed on your system.

[root@sms conf]# php --version

PHP 7.1.23 (cli) (built: Oct 10 2018 12:11:12) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies.

In my system, PHP version  7.1  is enabled.

2.  To enable Redis PHP extension on your CentOS server. Follow these commands below,

# pecl install igbinary igbinary-devel redis

In many of the system shows an error, -bash: pecl: command not found. To solve this , download the important PHP – Modules to enable the pecl command.

[root@sms ~]# yum install php-devel
[root@sms ~]# yum install php-pear

After installation of this PHP module, Pecl command is Enabled  . Now , Use the pecl to do a Redis PHP extension.

# pecl install igbinary igbinary-devel redis

3. After  executed  a  above command ,verify Redis PHP extension is enabled or not.

[root@sms ~]# php -m | grep redis

Redis server has been installed on your system along with the PHP extension.

Step 4 : Configure Redis as a Cache Server

Redis to make any  important changes you can use its configuration file  is: /etc/redis/redis.conf. Edit the Redis configuration file in a text editor to make changes,

1 . Configuring a Redis cache server.

[root@sms /]# cd /etc

[root@sms etc]# mkdir redis

[root@sms etc]# cd redis

[root@sms redis]# touch redis.conf

[root@sms redis]# nano redis.conf

2. Update the following values in Redis configuration file according to your requirement. You can increase max memory limit as per available on your server.

The above configuration tells Redis to remove any key using the LRU algorithm when the max memory of 256mb is reached. Save the configuration file.

3. Restart the Redis service.

[root@sms redis]# systemctl restart redis

Step 5 : Test Connection to Redis Server

Use redis-cli tool to verify the connection between Redis server and redis-cli. Check the Ping – pong Response in it.

[root@sms redis]# redis-cli

127.0.0.1:6379> ping

PONG

127.0.0.1:6379>

Thats it ! Redis ready for use.

Leave a Reply