How to enable caching on Nextcloud 16

Find out how to improve the performance of your Nextcloud cloud server by enabling caching.

How to enable caching on Nextcloud 16

Nextcloud is an incredibly powerful and flexible on-premises cloud server that any business (regardless of size) can make use of. Although out of the box, Nextcloud performs well, it is possible to gain significant increases in performance by enabling caching. Caching increases performance by storing frequently-requested objects in memory for faster retrieval.
I'm going to walk you through the process of setting up caching on Nextcloud 16, with the help of redis.

SEE: Hybrid cloud: A guide for IT pros (TechRepublic download)

What you'll need

All you will need to make this work is a running instance of Nextcloud and a user account with sudo privileges. 

How to install and configure Redis

The first thing to be done is the installation of Redis. To do this, open a terminal window on your Netcloud server and issue the command:

sudo apt-get install redis-server php-memcached memcached php-apcu -y

Start and enable redis with the command:

sudo systemctl start redis-server
sudo systemctl enable redis-server
sudo systemctl start memcached
sudo systemctl enable memcached

Once installed, you'll need to configure redis. Issue the command:

sudo nano /etc/redis/redis.conf

Edit the following lines to reflect these changes:

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

Save and close that file.

Next we must add redis to the www-data group, otherwise Nextcloud loading will fail. Do that with the command:

sudo usermod -aG redis www-data

How to configure Nextcloud

Now we have to configure Nextcloud. To do this, issue the command:

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

In that file, paste the following above the final ); line:

'memcache.local' => '\OC\Memcache\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' =>
   array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0,
    'password' => '',
    'dbindex' => 0,

Your file should look similar to that in Figure A.

Figure A


The bottom portion of a correctly configured config.php file.

Save and close that file. 

With Nextcloud configured, restart the web server with the command:

sudo systemctl restart apache2

How to configure php.ini

Finally, let's configure PHP Opcache (which is recommended by Nextcloud to improve basic functionality). To do this, issue the command:

sudo nano /etc/php/7.*/apache2/php.ini

Where * is the latest release of PHP installed on your system.

Go through that file (starting around line 1799) and make sure the following lines are configured as such (in many cases they need to simply be uncommented by removing the leading ; character):


Save and close that file.

Once again, restart Apache with the command:

sudo systemctl restart apache2

Open Nextcloud

Point your browser to your Nextcloud instance. The service should open as expected, only this time you have caching properly enabled. You should see a much-improved performance increase. Congratulations, you've fine-tuned Nextcloud to better meet the growing demand placed on your on-premises cloud server.

Also see


Image: Jack Wallen