If you’re currently running WordPress-based site you should consider to using Redis cache to optimize your site performance. On WordPress, redis is commonly using as database caching to improve site loading performance and reduce server resource. Especially if your server running low-memory / RAM or budget VPS. So, what’s actually Redis?

Redis is in-memory data structure storage which commonly used as a database cache, message broker and of course is an open-source software under BSD licensed. What you should noted that Redis has built-in replication, Lua scripting, transactions, LRU eviction, and different levels of on-disk persistence.

Redis also provide high-availability via Redis Sentinel and automatic partitioning with Redis Cluster. It’s mostly similar to memcached, which commonly used as a database caching on WordPress-based sites.

Well, on this today guide I will teach you on how to installing and configuring Redis cache on vps (virtual private server), cloud server running CentOS 7. This can be applied if you are running CLI-based server interface only or using control panel like VestaCP.

Let’s follow this guide to install Redis Cache.

REQUIREMENTS:
* VPS / Cloud / Dedicated Server running RHEL / CentOS 7
* Server IPv4 Address
* Server Full Root Access
* gNome Terminal or PuTTy SSH Client

1.) Install REMI Repository and EPEL Release

$ yum install epel-release
$ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo rpm -Uvh epel-release-latest-7*.rpm

$ wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ sudo rpm -Uvh remi-release-7*.rpm

$ wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm

$ yum --enablerepo=remi update remi-release

PLEASE NOTE: If you’re using PHP7+ and get some problems when configuring Redis cache, don’t forget to enable the following remi repository:

$ /etc/yum.repos.d/remi-php70.repo
$ /etc/yum.repos.d/remi-php71.repo
$ /etc/yum.repos.d/remi-php72.repo
$ /etc/yum.repos.d/remi-php73.repo
$ /etc/yum.repos.d/remi-php74.repo
$ /etc/yum.repos.d/remi-php80.repo

2.) Then, let’s install Redis Cache

$ yum install redis php-redis php-devel
$ yum install redis php80-php-redis php80-php-devel
$ yum install redis php74-php-redis php74-php-devel
$ yum install redis php73-php-redis php73-php-devel
$ yum install redis php72-php-redis php72-php-devel
$ yum install redis php71-php-redis php71-php-devel
$ yum install redis php70-php-redis php70-php-devel

OR if the above command not working, simmply run the following command.

$ yum --enablerepo=remi-php70 install redis php-redis php-devel
$ yum --enablerepo=remi-php71 install redis php-redis php-devel
$ yum --enablerepo=remi-php72 install redis php-redis php-devel
$ yum --enablerepo=remi-php73 install redis php-redis php-devel
$ yum --enablerepo=remi-php74 install redis php-redis php-devel
$ yum --enablerepo=remi-php80 install redis php-redis php-devel

3.) Enable and Start Redis Cache Service

After we’ve configure Redis Cache on CentOS 7 server, dont forget to enabled it and start redis cache service. Also, you should restart your web server as well, including Nginx / LiteSpeed / LigHTTPD / Apache HTTPD web server, and PHP-FPM service if you’re using it.

$ systemctl enable redis.service
$ systemctl restart redis.service
$ systemctl status redis.service

Let’s restart Web Server services:

$ service nginx restart
$ server httpd restart
$ service php-fpm restart
$ systemctl restart lighttpd.service
$ systemctl restart lighttpd.service
$ /usr/local/lsws/bin/lswsctrl restart

4.) To Monitoring Redis and Flush All Cache, simply run the following command.

$ redis-cli monitor
$ redis-cli
$ flushall
$ quit

5.) Redis Tuning Performance

So, you have installed and configured Redis Cache on your CentOS 7 machine. But, we must perform Redis tweaking via redis configuration file.

$ nano /etc/redis.conf

Looks for these lines...

# TCP listen() backlog.
#
#tcp-backlog 511 (default)
tcp-backlog 65536

# Unix socket.
#
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 60

# TCP keepalive.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 120

################################### CLIENTS ####################################

# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
maxclients 10000

# Maximal effort for defrag in CPU percentage
# active-defrag-cycle-max 75
maxmemory 256mb
maxmemory-policy allkeys-lru

6.) Restart Redis Cache Service

After that, don’t forget to restart Redis cache services.

$ systemctl restart redis.service

CONCLUSION:

Installing and configuring Redis Cache service is quite easy, but you must having relax time to install Redis. Based on my experience so far, Redis or Memcached can improve WP site performances via database caching features. It should improve your site load times and reduce server load, both memory and CPU Usage.

LEAVE A REPLY

Please enter your comment!
Please enter your name here