• Joel

Enabling Redis LRU caching for your Nextcloud server



Prerequisites

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

Introduction

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>:

<?php
$CONFIG = array (
  'instanceid' => 'ocvtfvhdwjai',
  'passwordsalt' => 'O18XcdsdsdcQfFuN8AkvVf+e87',
  'secret' => 'Mkk/o5h319wsdG/vl1jEZGnlZRZqJYSs9iUM',
  'trusted_domains' =>
  array (
    0 => '192.168.0.10',
    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' => '18.0.3.0',
  'overwrite.cli.url' => 'http://192.168.0.10/nextcloud',
  '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>:

opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

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.

0 views
  • Facebook
  • Instagram

©2020 by BitProof Web design