For those of you who didn’t know, Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. 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.
This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation Redis on CentOS 6.
Step 1. First, you need to enable EPEL repository on your system.
1 2 3 4 5 6 7 | ## RHEL/CentOS 6 64-Bit ## # wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # rpm -ivh epel-release-6-8.noarch.rpm ## RHEL/CentOS 6 32-Bit ## # wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm # rpm -ivh epel-release-6-8.noarch.rpm |
Step 2. Install Redis with Yum.
1 2 | yum-yupdate yuminstallredisphp-pecl-redis |
Enable Redis service to start on boot:
1 2 | serviceredisstart chkconfigredison |
Check if Redis is Running:
1 2 | ### chkconfig –list redis redis0:off1:off2:on3:on4:on5:on6:off |
To make sure redis is working, run command “redis-cli ping” from commandline. If you get result “PONG”, that shows redis is working.
Step 3. Install Redis PHP extension.
After we have Redis installed we will need the PHP-REDIS extension. Using following command:
1 | peclinstallredis |
Now open php.ini file and add the following line to it:
1 2 | ### nano /etc/php.ini extension=redis.so |
Now restart Apache to apply the changes to php.ini file:
1 | servicehttpdrestart |
Step 4. Install web interface for Redis.
phpRedisAdmin is a simple web interface to manage Redis databases:
1 2 3 | gitclonehttps://github.com/ErikDubbelboer/phpRedisAdmin.git cdphpRedisAdmin/includes cpconfig.sample.inc.phpconfig.inc.php |
Make sure the setting are correct:
1 | nanoconfig.inc.php |
Lets add the RedisAdmin configuration file to Apache:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ### nano /etc/httpd/conf.d/redisadmin.conf ### Now add the following ### # # Web Interface for RedisAdmin # <Directory"/downloads/phpRedisAdmin/"> OrderDeny,Allow Denyfromall Allowfrom127.0.0.1 Allowfrom<youripaddress> </Directory> Alias/redisAdmin/downloads/phpRedisAdmin Alias/redisadmin/downloads/phpRedisAdmin |
Create a Bash Script to make sure Redis is running:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ### nano /scripts/redis-check.sh #!/bin/bash PS=$(whichps) GREP=$(whichgrep) WHEN=$(date+"%Y-%m-%d-%H:%M:%S") if !$PSaux|$GREP"redis.conf"|$GREP-vgrep2>&1>/dev/null;then /etc/init.d/redisrestart echo'Restarted Redis @'$WHEN fi #Check Second instance if !$PSaux|$GREP"redis2.conf"|$GREP-vgrep2>&1>/dev/null;then /etc/init.d/redis2restart echo'Restarted Redis2 @'$WHEN fi |
Make the Script executable:
1 | chmod+x/scripts/redis-check.sh |
Add your script to your cron to run every 3 minutes or so:
1 2 | ### nano /var/spool/cron/root */3****/bin/bash/script/redis-check.sh>>/var/log/redis-check.log |
Congratulation’s! You have successfully installed Redis. Thanks for using this tutorial for installing Redis server on CentOS 6 system.