How to Speed Up WordPress Using Redis Caching

How to Speed Up WordPress Using Redis Caching

WordPress is software designed for everyone, emphasizing accessibility, performance, security, and ease of use. WP believe great software should work with minimum set up, so you can focus on sharing your story, product, or services freely. The basic WordPress software is simple and predictable so you can easily get started. It also offers powerful features for growth and success.

But in non-geek speak, it’s probably the easiest and most powerful blogging and website content management system (or CMS) in existence today.

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 and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation WordPress content management systems on a Ubuntu 16.04 server.

Speed Up WordPress Using Redis Caching

Step 1. First make sure that all your system packages are up-to-date

sudo apt-get update
sudo apt-get upgrade

Step 2. Installing WordPress

If you do not have WordPress installed, you can follow WP Installation guide here.

Step 3. Installing Redis.

In order to use Redis with WordPress, two packages need to be installed: redis-server and php-redis. The redis-server package provides Redis itself, while the php-redis package provides a PHP extension for PHP applications like WordPress to communicate with Redis:

apt-get install redis-server
apt-get install php-redis

Start and enable Redis on system boot:

systemctl start redis.service
systemctl enable redis.service

Step 4. Install Redis Caching Plugin in WordPress.

After installing Redis and the PHP Redis client extension, log in to your WordPress Dashboard and select Add New from the Plugins menu.

Then, search for “Redis Object Cache” and click Install Now on the matching result.

redis-object-cache
Next, navigate to Settins > Redis and click on Enable Object Cache to enable the object caching in WordPress. The default configuration should work out of the box sonce the default Redis listening address is 127.0.0.1 and the default listening port is 6379.

Step 5. Verify WordPress caching.

To check whether the WordPress caching works OK with Redis you can connect to your server via SSH and run the following command:

redis-cli monitor

When you run this command, you will see the real-time output of Redis serving cached queries. If you don’t see anything, visit your website and reload a page.

Congratulation’s! You have successfully installed WordPress with Redis Caching.

How To Install Redis on Ubuntu 18.04 LTS

Install Redis on Ubuntu 18

Redis is a in memory key-value data structure store mainly used as a database, message broker or as a cache. Redis supports wide languages with flexibility and high performance. It supports different data structures like strings, lists, sets, maps, spatial indexes, and bitmaps.

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 and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Redis on an Ubuntu 18.04 bionic beaver.

Install Redis on Ubuntu 18.04 LTS Bionic Beaver

Step 1. First, make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Installing Redis on Ubuntu.

The Redis packages are available under the default apt repository. For the installation of Redis on an Ubuntu. Run below command from the terminal to install Redis on your machine:

sudo apt install redis-server

Redis provide php extension to work with php. Here we will cover installation of Redis Extension of php from source compilation and using apt repository. Following command will install and setup redis extension with php:

sudo apt install php-redis

Once the installation is completed, Redis service will start automatically. To check the status of the service enter the following command:

sudo systemctl status redis-server

Step 3. Configure Redis Cache.

To configure Redis as a cache you need to edit the /etc/redis/redis.conf file:

sudo nano /etc/redis/redis.conf
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0 ::1
1
2
3
4

# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind0.0.0.0::1

Restart the Redis service for changes to take effect:
sudo systemctl restart redis-server
1

sudosystemctlrestartredis-server

We will now test the Redis instance with some commands:
$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set test "Redis Working!"
OK
127.0.0.1:6379> get test
"Redis Working!"
127.0.0.1:6379> exit

Congratulation’s! You have successfully installed Redis. Thanks for using this tutorial for installing Redis in Ubuntu 18.04 bionic beaver system. For additional help or useful information, we recommend you to check the official Redis website.

How To Install Redis on Ubuntu 16.04 LTS

Install Redis on Ubuntu 16

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 and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Redis on a Ubuntu 16.04 LTS (Xenial Xerus) server.
Install Redis on Ubuntu 16.04 LTS

Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

sudo apt-get update
sudo apt-get upgrade

Step 2. Installing Redis.

Installing Redis on an Ubuntu is simple. Run the command below to install Redis on your machine:

apt-get install redis-server

Redis provide php extension to work with php. Here we will cover installation of Redis Extension of php from source compilation and using apt repository. Following command will install and setup redis extension with php:

apt-get install php-redis

Step 3. Configure Redis Cache on Ubuntu 16.04.

To configure Redis as a cache you need to edit the /etc/redis/redis.conf file:

nano /etc/redis/redis.conf

To configure the max memory for Redis as well as how Redis will select what to remove when the max memory is reached, add the following lines at the end of the file:

maxmemory 128mb
maxmemory-policy allkeys-lru

Save and close the file, then restart the Redis service:

systemctl restart redis-server.service
systemctl enable redis-server.service

Step 4. Starting and Testing the Redis.

We will start and check the status of the Redis with the below commands:

$ systemctl start redis-server.service
$ systemctl status redis-server.service
redis.service - Redis In-Memory Data Store
Loaded: loaded (/etc/systemd/system/redis.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2016-10-20 15:07:10 IST; 17s ago
Main PID: 7207 (redis-server)
Tasks: 3
Memory: 6.2M
CPU: 22ms
CGroup: /system.slice/redis.service
└─7207 /usr/local/bin/redis-server 127.0.0.1:6379
Oct 20 15:07:10 ubuntu-16 redis-server[7207]:  |    `-._`-._        _.-'_.-'    |
Oct 20 15:07:10 ubuntu-16 redis-server[7207]:   `-._    `-._`-.__.-'_.-'    _.-'
Oct 20 15:07:10 ubuntu-16 redis-server[7207]:       `-._    `-.__.-'    _.-'
Oct 20 15:07:10 ubuntu-16 redis-server[7207]:           `-._        _.-'
Oct 20 15:07:10 ubuntu-16 redis-server[7207]:               `-.__.-'
Oct 20 15:07:10 ubuntu-16 redis-server[7207]: 7207:M 20 Dec 16:07:10.853 # WARNING: The T
Oct 20 15:07:10 ubuntu-16 redis-server[7207]: 7207:M 20 Dec 16:07:10.853 # Server started
Oct 20 15:07:10 ubuntu-16 redis-server[7207]: 7207:M 20 Dec 16:07:10.853 # WARNING overco
Oct 20 15:07:10 ubuntu-16 redis-server[7207]: 7207:M 20 Dec 16:07:10.853 # WARNING you have.
...
...

We will now test the Redis instance with some commands:

$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set test "Redis Working!"
OK
127.0.0.1:6379> get test
"Redis Working!"
127.0.0.1:6379> exit

Congratulation’s! You have successfully installed Redis. Thanks for using this tutorial for installing Redis on your Ubuntu 16.04 system. For additional help or useful information, we recommend you to check the official Redis web site.