Redis over a Unix socket for Nextcloud caching
Configure Redis on a Unix socket and enable it as cache and locking backend in Nextcloud.
This note describes how to configure Redis over a Unix socket and use it as a cache and file-locking backend for Nextcloud on Linux (Arch-style paths).
Configure the Unix socket
Edit /etc/redis/redis.conf:
unixsocket /run/redis/redis.sock
unixsocketperm 770
Manage the service
sudo systemctl enable redis.service
sudo systemctl start redis.service
sudo systemctl stop redis.service
sudo systemctl status redis.service
Test
redis-cli -s /run/redis/redis.sock
redis-cli ping
# check the web application user can reach Redis
sudo su -s /bin/bash -c 'whoami' nextcloud
sudo su -s /bin/bash -c 'redis-cli ping' nextcloud
sudo su -s /bin/bash -c 'redis-cli -s /run/redis/redis.sock' nextcloud
Nextcloud configuration
Install the PHP extensions needed (APCu, igbinary, imagick, memcache, redis) with your package manager, then enable them in the PHP configuration:
sudo vim /etc/php-legacy/conf.d/apcu.ini
sudo vim /etc/php-legacy/conf.d/igbinary.ini
sudo vim /etc/php-legacy/conf.d/imagick.ini
sudo vim /etc/php-legacy/conf.d/memcache.ini
sudo vim /etc/php-legacy/conf.d/redis.ini
In /etc/webapps/nextcloud/php.ini, add /run/redis to open_basedir:
open_basedir=/var/lib/nextcloud:/tmp:/usr/share/webapps/nextcloud:/etc/webapps/nextcloud:/dev/urandom:/usr/lib/php-legacy/modules:/var/log/nextcloud:/proc/meminfo:/proc/cpuinfo:/run/redis
Then in /etc/webapps/nextcloud/config/config.php:
'memcache.local' => '\\OC\\Memcache\\APCu',
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' => array (
'host' => '/run/redis/redis.sock',
'port' => 0,
'dbindex' => 0,
'timeout' => 1.5,
),
Notes
- The Unix socket must be readable by the web server / Nextcloud user (hence the
770permission and group membership).