Menu Close

NextCloud Memory Caching – Redis configuration

You can significantly improve your Nextcloud server performance with memory caching, where frequently-requested objects are stored in memory for faster retrieval.

Recommended caches are APCu and Redis. Both a local and a distributed cache can be used at the same time.

Step 1 : Install APCu and Redis

  • On Debian/Ubuntu install php- apcu redis-server php-redis
  • On CentOS install php-pecl-apcu redis php-pecl-redis

Step 2 : Configure Redis

Check which user redis is running on

  • # ps aux | grep redis

Add web server user to the redis group

  • Debian/Ubuntu # usermod -g www-data redis
  • CentOS # usermod -g apache redis

If Redis is running on the same system as NextCloud, it is recommended to configure connect Redis listen on an Unix socket.

Create the directory for the unix socket and add permission

  • # mkdir -p /var/run/redis/
  • add permission
  • Debian/Ubuntu # chown -R redis:www-data /var/run/redis
  • CentOS # chown -R redis:apache /var/run/redis

Configure /etc/redis/redis.conf

  • comment out unixsocket and unixsocketperm
  • change unixsocketperm 700 to 777 or else the cache cannot be erased

Restart redis

  • # systemctl restart redis

Step 3 : Configure Redis for NextCloud

  • # vim /var/www/html/nextcloud/config/config.php

Add below to the config.php

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

Set the right permission for redis.sock so your web server can read and write to it, restart apache

  • Debian/Ubuntu # usermod -a -G redis www-data
  • CentOS # usermod -a -G redis apache
  • # systemctl restart httpd

Verify if Redis is running

  • # ls -lh /var/run/redis

More on Redis setup :

Nextcloud 17 Administration Manual:

Leave a Reply

Your email address will not be published. Required fields are marked *