cPanel

Install Redis on cPanel with EasyApache 3

EasyApache 3
install redis

Install Redis on cPanel with EasyApache 3

This post describes how to install Redis on cPanel/CentOS 6 with EasyApache 3. Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.

You can find the installation of Redis on cPanel with EasyApache 4 from Here

Also, read more about Redis from here.

Steps to install Redis Daemon

1. Download the current stable version of Redis from here.

2. Installation

 
cd /usr/local/src/
wget http://download.redis.io/releases/redis-3.0.5.tar.gz
tar -xvzf redis-3.0.5.tar.gz
cd redis-3.0.5
make
make install
cp /usr/local/src/redis-3.0.5/src/redis-server /usr/local/bin/
mkdir /etc/redis
mkdir /var/redis
cp /usr/local/src/redis-3.0.5/redis.conf /etc/redis/redis.conf

Open the file “/etc/redis/redis.conf” using vi editor and set the following values.

 
daemonize yes
port 6379
bind 127.0.0.1
dir /var/redis/
logfile /var/log/redis.log
pidfile /var/run/redis.pid

Then you need to add a start-up script. Create a file “/etc/init.d/redis” using vi editor and add the following contents.

 
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15 
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
redis="/usr/local/bin/redis-server"
prog=$(basename $redis)
 
REDIS_CONF_FILE="/etc/redis/redis.conf"
 
[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
 
lockfile=/var/lock/subsys/redis
 
start() {
 [ -x $redis ] || exit 5
 [ -f $REDIS_CONF_FILE ] || exit 6
 echo -n $"Starting $prog: "
 daemon $redis $REDIS_CONF_FILE
 retval=$?
 echo
 [ $retval -eq 0 ] && touch $lockfile
 return $retval
}
 
stop() {
 echo -n $"Stopping $prog: "
 killproc $prog -QUIT
 retval=$?
 echo
 [ $retval -eq 0 ] && rm -f $lockfile
 return $retval
}
 
restart() {
 stop
 start
}
 
reload() {
 echo -n $"Reloading $prog: "
 killproc $redis -HUP
 RETVAL=$?
 echo
}
 
force_reload() {
 restart
}
 
rh_status() {
 status $prog
}
 
rh_status_q() {
 rh_status >/dev/null 2>&1
}
 
case "$1" in
 start)
 rh_status_q && exit 0
 $1
 ;;
 stop)
 rh_status_q || exit 0
 $1
 ;;
 restart|configtest)
 $1
 ;;
 reload)
 rh_status_q || exit 7
 $1
 ;;
 force-reload)
 force_reload
 ;;
 status)
 rh_status
 ;;
 condrestart|try-restart)
 rh_status_q || exit 0
 ;;
 *)
 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
 exit 2
esac

Make the start-up script file executable.

 
chmod 755 /etc/init.d/redis

Enable the redis daemon on chkconfig. It will make sure the redis daemon automatically start after the server reboot.

 
chkconfig --add redis
chkconfig redis on

Then, start the redis daemon.

 
/etc/init.d/redis start

You now have Redis installed and running. The prompt will look like this:

 
root@server [~]# redis-cli
127.0.0.1:6379>

Run command “redis-cli ping” to make sure redis is working. It will provide an output “PONG” if the redis is installed properly.

 
root@server [~]# redis-cli ping
PONG
root@server [~]#

Install redis PHP extension on cPanel using EasyApache 3

 
pecl install redis

Now open php.ini ( /usr/local/lib/php.ini on cPanel servers ) file and add the following line to it.

 
extension=redis.so

Now restart Apache to apply the changes to php.ini file.

service httpd restart

That’s it!

If you like this post and wish to receive more articles from us, please like our FB page: Grepitout

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.

For more details on our services, please drop us an E-mail at info@grepitout.com

1 Comment

Click here to post a comment

Topics