Install and run WordPress cached with Redis on a Linux VPS

redisWordPress page loading speed can be very slow, especially if your site have many visitors and/or you use a lot of plugins. Caching is the best way to improve the loading speed of a WordPress website and overall users experience. In this guide, we will walk you through the basic installation process of WordPress on an Ubuntu 14.04 VPS. with Nginx, MariaBD and PHP FPM and setting up a Redis cache to boost WordPress performance. This should work on other Linux VPS systems as well but was tested and written for Ubuntu 14.04.

Update the system and install necessary packages.

apt-get -y update && apt-get -y upgrade
apt-get install software-properties-common curl git

Install the latest stable version of Redis

apt-add-repository ppa:chris-lea/redis-server
apt-get update
apt-get install redis-server

Install MariaDB 10.0

apt-key adv --recv-keys --keyserver hkp:// 0xcbcb082a1bb943db
add-apt-repository 'deb trusty main'
apt-get update
apt-get install mariadb-server

When installation complete, run the following command to secure your installation:


Next, we need to create a database for our WordPress instance.

mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE wpdb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'wpuser_passwd';
MariaDB [(none)]> \q

Install PHP and Nginx

The latest version of Nginx 1.6.2 is not available via the default Ubuntu repositories, so we will add the “nginx/stable” PPA, update the system and install the nginx package.

add-apt-repository ppa:nginx/stable
apt-get update
apt-get install nginx php5-fpm php-cli php5-gd php5-mysqlnd

Nginx configuration

Create a new Nginx server block with the following content:

nano /etc/nginx/sites-available/
server {
  listen 80;
  root /var/www/;
  access_log /var/www/;
  error_log /var/www/;
  index index.php;

  location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;

  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;

  location ~ /\.ht {
    deny  all;

  location ~ \.php$ {
    fastcgi_index index.php;
    fastcgi_keep_conn on;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Activate the server block by creating a symlink:

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Test the Nginx configuration and restart the server by running the following commands:

nginx -t
/etc/init.d/nginx restart

Install WordPress

Create a new directory for your WordPress site:

mkdir -p /var/www/{public_html,logs}

Download and extract the WordPress package:

wget -q -O - | tar -xzf - --strip 1 -C /var/www/

Set the correct permissions:

chown www-data: -R /var/www/

Finally run the WordPress installation script by accessing the URL in your web browser of choice.

Redis Cache

Clone the BenjaminAdams/wp-redis-cache github repository:

 git clone /tmp/wp-redis-cache

Move index.php and index-wp-redis.php to your WordPress directory.

 mv /tmp/wp-redis-cache/{index-wp-redis.php,index.php} /var/www/

Open the index-wp-redis.php file and change $websiteIp with your server IP address, and $secret_string with a random string.

Move the wp-redis-cache diectory to your WordPress plugin directory and activate the plugin via the ‘Plugins’ menu in WordPress.

mv /tmp/wp-redis-cache/wp-redis-cache /var/www/

Please note, sometimes when you upgrade WordPress it will overwrite the index.php file and you will have to manually change the index.php to:


For more information about wp-redis-cache please check the file.

Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately. You can also consider reading our post on How to Speed Up WordPress with Redis Caching.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

5 thoughts on “Install and run WordPress cached with Redis on a Linux VPS”

    • hi,

      you can check if redis is caching by using its cli tool known as ‘redis-cli’, for example:

      redis-cli MONITOR

      to learn more on how to use ‘redis-cli’ please refer to redis official documentation at and

  1. Redis is an awesome cache. I found I had to set the following in the redis.conf:

    maxmemory 256mb #(or your max mem you want to use)
    maxmemory-policy allkeys-lru

    The default was 0 which meant ‘unlimited’ – the server would literally run out of RAM and the host would grind to a halt.


Leave a Comment

To prove you are human please solve the following *