Configuring redis memcache for file locking on Centos 7

Having battled with this for several hours, I’m documenting this for posterity. My client’s Nextcloud was already configuring using APUc for local caching but since the last upgrade, you get the following warning:

The database is used for transactional file locking. To enhance performance, please configure memcache, if available

These are the steps I followed to get redis caching working on a standalone Nextcloud server. Assumes you’re running as sudo. If not, you’ll need sudo prefixes here and there.

Install redis and PHP module

Installs the packages, enables & starts the service and checks working via port.

yum -y install redis php-redis
systemctl enable redis --now
redis-cli ping

Change to using a socket

By default, redis binds to a TCP port. This change is recommended for standalone servers and changes it to use a socket. You edit the file, restart the service and check it’s working.

nano /etc/redis.conf
systemctl restart redis
redis-cli -s “/var/run/redis/redis.sock” ping

The following changes are made to redis.conf:

  1. Comment out bind 127.0.0.0 line
  2. Change port to 0
  3. Uncomment unixsocket /var/run/redis/redis.sock
  4. Uncomment unixsocketperm 777

Reconfigure Nextcloud to use redis

Edit the Nextcloud PHP configuration file (change path as required) and restart all the services. After doing this, the warning message should go away.

nano /data/nextcloud/config/config.php
systemctl restart nginx php-fpm redis

Add the following variables to config.php:

‘redis’ => [
  â€˜host’ => ‘/var/run/redis/redis.sock’,
  â€˜port’ => 0,
  â€˜timeout’ => 0.0,
],
‘memcache.locking’ => ‘\OC\Memcache\Redis’,

3 Likes

Not sure if this is connected at all, but I had lots of locked 423 errors in the client which have just magically all just sorted themselves out.

For other distributions that package nexctcloud-server, make sure that open_basedir is or isn’t set in one of the package config files (generally nextcloud.conf). If it is, add the redis runtime directory to the open_basedir path. (caused me the same amount of pain on Arch)

1 Like