How to make your NextCloud faster with Redis as an in-memory cache using Docker?

I’m obsessed with optimizing things. Already I’ve optimized my VPS in a few different aspects: Apache webserver + PHP-FPM, MariaDB database, and all of my websites using Cloudflare and some more tricks.

Now I’m focused on my cloud storage – NextCloud. Let’s make it blazing fast with Redis as an in-memory cache.

So, we need to make our hands dirty. Only a little, calm down, everybody calms down!

I assume You already have installed docker on your machine. If not, search for a tutorial that will suit your Linux distribution.

Also, You should have php-redis module already installed!

Create a docker container

Below You can find a command that will create a Redis docker container for your NextCloud installation. Customize command as You wish by necessarily changing REDIS_PASSWORD and maybe binded host port (-p 6363:6379) and container name (–name).

docker run -d \
  -h redis \
  -e REDIS_PASSWORD=<your_password_here> \
  -p 6363:6379 \
  --name redis_nextcloud \
  --restart always \
  redis /bin/sh -c 'redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}'

Add Redis container to NextCloud configuration

Now we need to add a few lines to our NextCloud configuration. Open config.php file which is located in below path:

nano /<your_nextcloud_path>/config/config.php

Let’s link our docker container with NextCloud by adding the below lines to the configuration file. We will be using Redis for the distributed server cache and also for file locking.

Change values to match your configuration!

  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'redis' =>
    array (
      'host' => '', //if you binded port you can use localhost:6363 or
      //'host' => 'docker', //you can add docker alias to /etc/hosts
      'port' => 6379,
      'password' => '<your_password>',

Refresh your NextCloud page or reboot web server – it will be needed in some cases. If there are no errors on the home page everything worked like a charm.

Now enjoy the speed!

Join my Newsletter! 👨‍💻

Subscribe to get my latest content by email 🦾

Also read...

The best entries...