• Joel

Enabling Redis LRU caching for your Nextcloud server


You'll need to have completed the following guide in this series:



So you may be asking, "What the hell is an LRU cache anyway?". LRU stands for Least Recently Used, which means Redis will automatically evict old data as new data is added. Doing this will vastly improve your overall experience in using Nextcloud. We'll be installing Redis; then we'll be configuring three config files: Redis, Nextcloud and PHP.

Let's get started...


Installing and configuring Redis LRU caching

First, you'll need to download and install Redis by running the following command:

$ sudo apt-get install redis-server

Let's now start and enable Redis for boot:

$ sudo systemctl start redis-server
$ sudo systemctl enable redis-server

Now, you'll need to edit the Redis configuration file:

$ sudo nano /etc/redis/redis.conf

Edit the following options, ensuring they're not commented out. Save the file by pressing <Ctrl> + x followed by Y and then press <Enter>:

port 0
unixsocket /var/run/redis/redis.sock
unixsocketperm 770

We now need to add Redis to the www-data group:

$ sudo usermod -aG redis www-data

Configuring Nextcloud

We now need to configure Nextcloud, so that it uses Redis caching. Let's do this by editing the Nextcloud configuration file:

$ sudo nano /var/www/nextcloud/config/config.php

Now to add the Redis cache settings. This can be tricky for some reason. However, after trial and error we got there, by placing the settings in the following location (positioning is important). Text to add is in red. Save the file by pressing <Ctrl> + x followed by Y and then press <Enter>:

$CONFIG = array (
  'instanceid' => 'ocvtfvhdwjai',
  'passwordsalt' => 'O18XcdsdsdcQfFuN8AkvVf+e87',
  'secret' => 'Mkk/o5h319wsdG/vl1jEZGnlZRZqJYSs9iUM',
  'trusted_domains' =>
  array (
    0 => '',
    1 => 'www.joescloud.dynamic-dns.net',
    3 => 'https://www.joescloud.dynamic-dns.net',
    4 => 'https://joescloud.dynamic-dns.net',
  'datadirectory' => '/media/data',
  'dbtype' => 'mysql',
  'version' => '',
  'overwrite.cli.url' => '',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'nextcloud',
  'installed' => true,
'memcache.local' => '\OC\Memcache\Redis',
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'filelocking.enabled' => 'true',
'redis' =>
array (
'host' => '/var/run/redis/redis.sock',
'port' => 0,
'timeout' => 0.0,

You now need to restart the web server service:

$ sudo systemctl restart apache2

Configuring PHP

Assuming you have PHP version 7.3 installed, run the following to edit your PHP file:

$ sudo nano /etc/php/7.3/apache2/php.ini

Now you'll need to find the following options and uncomment them out, by removing the leading ';' for each. Double-check the values are correct too. These options are quite far down the file; near line #1800. Save the file by pressing <Ctrl> + x followed by Y and then press <Enter>:


Finally, I would recommend that restart your Raspberry Pi:

$ sudo reboot

You should now see a performance improvement when navigating and accessing files in your Nextcloud server.

367 views0 comments

Recent Posts

See All