Speed Up Wordpress With Redis Object Cache

Page content

Install Redis Object Cache on Apache Server Ubuntu 22.04

Wordpress is an awesome content management system that is used by millions across the globe to power their sites. It works with a mysql or mariadb database.

However, Wordpress websites need to be cached to load faster. Otherwise, they will load slow and can load very slow if you are using too many plugins on your website.

It is also recommended to use some form of object cache with your wordpress website. Object caching can significantly improve Wordpress speed and performance.

In this post, we will show you how to install Redis and speed up your Wordpress website.

Wordpress depends heavily on the mysql database and therefore, it is critical to manage database efficiency to maintain Wordpress performance.

Every time a request is made, Wordpress has to query the database to send the response. However, this can lead to increased pressure on the server and slow responses. This is where caching proves useful since items stored in the cache can be served to the user directly without needing a response from the origin server each time.

Object caching stores database query results so that each time a request is made the response does not need to be served from the database or each time the database does not need to be queried.

In the case of sites with heavy traffic, the server can quickly grow overwhelmed due to the high number of requests if object caching is not enabled.

Object cache offers two main advantages. First of all, you can access data in milliseconds. The data retrieval process is sped up since the data is available in cache and can be served to the users directly. Moreover, it speeds up php execution and leads to optimized website performance.

Second, object cache minimizes the number of requests being made to the sql database. It delivers cached content and reduces the load on the server especially during the peak times.

With Wordpress, you can use mainly two types of object cache including Memcached and Redis. Both are types of persistent object caching and can significantly improve load times. They are powerful in-memory data stores that can significantly reduce the load on the database and improve website speed. However, Redis has grown more popular with time because of being more feature rich.

Install redis Cache on Ubuntu 22.04

If you are using managed Wordpress hosting, you must check out if your hosting provider offers Redis cache. There are some hosting providers like Cloudways that offer free Redis cache. It is easy to enable Redis cache with just a single click in such a scenario. Otherwise, you can easily install it on Linux servers.

The installation of Redis Object Cache on Ubuntu 22.04 and wordpress can be completed in four simple steps:

  • Install Redis

  • Install Redis PHP extension

  • Install Redis cache plugin for Wordpress

  • Verify Redis is working

You will need ssh access to your server. Connect to your server and run the following commands:

Sudo apt update
Sudo apt install redis -y

This will install the redis cache on your server. Now, we need to install the redis php extension:

Sudo apt install php-redis

Check if Redis is running:

Sudo systemctl status redis

If you receive an output like the following, it shows that Redis is active on your server and running:

sudo systemctl status redis
● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2024-05-20 14:36:59 UTC; 1h 50min ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 315483 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4575)
     Memory: 20.2M
        CPU: 18.723s
     CGroup: /system.slice/redis-server.service
             └─315483 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">

May 20 14:36:59 ip-172-31-23-57 systemd[1]: Starting Advanced key-value store...
May 20 14:36:59 ip-172-31-23-57 systemd[1]: Started Advanced key-value store.

You can start and enabled Redis with the following commands if it is not active:

Sudo systemctl start redis
Sudo systemctl enable redis

To stop redis:

Sudo systemctl stop redis

And to restart it:

Sudo systemctl restart redis

We have installed Redis and the php-redis extension. Now, we can install the Redis cache plugin on Wordpress.

You will need to install the Redis object cache plugin by Til Kruss on Wordpress, which is the most popular Redis plugin for Wordpress. It has more than 100,000 active installations and 4.5 star ratings. The plugin is free to use.

Redish Cache Plugin

Install this plugin from the wordpress repository and then activate it. To start using redis on Wordpress, go to the plugin settings and click on the enable button to enable Redis.

Now, you can verify that Redis is working. Connect to your server and run the following command:

Redis-cli monitor

You will receive a response like the following which shows that redis is working as expected:

redis-cli monitor
OK
1716222910.590380 [0 127.0.0.1:42904] "PING"
1716222910.590457 [0 127.0.0.1:42904] "INFO"
1716222910.591146 [0 127.0.0.1:42904] "GET" "wp:default:is_blog_installed"
1716222910.594123 [0 127.0.0.1:42904] "GET" "wp:options:alloptions"
1716222910.610434 [0 127.0.0.1:42904] "GET" "wp:site-options:1-notoptions"
1716222910.612497 [0 127.0.0.1:42904] "GET" "wp:translation_files:cb8eeab119d406a9929800f6b8623bda"
1716222910.612719 [0 127.0.0.1:42904] "GET" "wp:translation_files:de2c81ef2bfe9c9f5fc822105098dce3"
1716222910.615887 [0 127.0.0.1:42904] "GET" "wp:options:gzipcompression"
1716222910.615972 [0 127.0.0.1:42904] "GET" "wp:options:notoptions"
1716222910.617883 [0 127.0.0.1:42904] "GET" "wp:options:wpcode_settings"
1716222910.628512 [0 127.0.0.1:42904] "GET" "wp:transient:dst_upgraded_ad-inserter"
1716222910.629374 [0 127.0.0.1:42904] "GET" "wp:translation_files:b76932fc2652befec3ba87af8399d702"
1716222910.634030 [0 127.0.0.1:42904] "GET" "wp:options:uag_visibility_mode"
1716222910.634139 [0 127.0.0.1:42904] "GET" "wp:options:uag_visibility_page"
1716222910.636359 [0 127.0.0.1:42904] "GET" "wp:options:uag_enable_templates_button"
1716222910.637877 [0 127.0.0.1:42904] "GET" "wp:options:zip_ai_modules"
1716222910.642254 [0 127.0.0.1:42904] "GET" "wp:translation_files:a034bf2fb0aa05f08eedb14b27d96559"
1716222910.644348 [0 127.0.0.1:42904] "GET" "wp:translation_files:9076bcfa64fe32611b29d059b9256f15"
1716222910.653500 [0 127.0.0.1:42904] "GET" "wp:options:widget_text"
1716222910.653664 [0 127.0.0.1:42904] "GET" "wp:options:widget_categories"
1716222910.660724 [0 127.0.0.1:42904] "GET" "wp:theme_files:wp_theme_patterns_generatepress"
1716222910.663400 [0 127.0.0.1:42904] "GET" "wp:options:uag_enable_coming_soon_mode"
1716222910.663670 [0 127.0.0.1:42904] "GET" "wp:options:uag_coming_soon_page"
1716222910.667944 [0 127.0.0.1:42904] "GET" "wp:options:alloptions"

Now, you can also try reloading your webpages and you will see that they are loading faster.