Installing Redis for Memcache

I’m having trouble with setting up Redis. I wanted to get rid of the message telling me to optimize memcache so i began following the instructions here: Memory caching — Nextcloud latest Administration Manual latest documentation

My server info is this:
Nextcloud version: 24.0.12
Operating system and version : “Ubuntu 22.04”
Apache: Apache/2.4.52`
PHP version: 7.4

I edited the /nextcloud/config/config.php file and added according to the doc above:

'memcache.locking' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => [
     'host'     => '/run/redis/redis-server.sock',
     'port'     => 0,
     'dbindex'  => 0,
     'password' => 'secret',
     'timeout'  => 1.5,
]
);

I also edited the /etc/redis/redis.config file by removing the comments from these lines:

 unixsocket /var/run/redis/redis-server.sock
 unixsocketperm 770

I also changed permissions by running this command according to the doc:

usermod -a -G redis www-data

I’ve restarted redis, apache2, and php7.4-fpm

But now i get a “Internal Server Error”

Running the systemctl status redis, i get this:

redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-05-22 02:48:41 UTC; 7min ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 401534 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4456)
     Memory: 2.5M
        CPU: 452ms
     CGroup: /system.slice/redis-server.service
             └─401534 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">

Does anyone know what I’m doing wrong?

Thanks!

I also changed the port on the config/php file to 6379, but even after restarting the server it still gives me the Internal Server Error.

I noticed three things that should be adjusted…

1. The path for the UNIX socket

The path for the UNIX socket is set differently in redis.conf and config.php. Adjust the path in Nextcloud’s config.php like this:

'redis' => [
     'host'     => '/var/run/redis/redis-server.sock',
     'port'     => 0,
     'dbindex'  => 0,
     'password' => 'secret',
     'timeout'  => 1.5,

2. Enable the UNIX Socket

Set the port to 0 in In /etc/redis/redis.conf. This disables the TCP socket and enables the UNIX socket:

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 0

3. Passwod Authentication

Either delete the following line in the config.php

     'password' => 'secret',`

…or enable password authentication in /etc/redis/redis.conf, like this:

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass secret

I’ve made the changes you’ve recommended but I still get this error when visiting the server:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

How can i troubleshoot this further? Thanks!

I notice when i run systemctl status redis-server.service, i get this message:

× redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2023-05-27 09:30:33 UTC; 5min ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
    Process: 1384 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no (code=exited, status=1/FAILURE)
   Main PID: 1384 (code=exited, status=1/FAILURE)
        CPU: 40ms

May 27 09:30:33 cloud-us systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
May 27 09:30:33 cloud-us systemd[1]: Stopped Advanced key-value store.
May 27 09:30:33 cloud-us systemd[1]: redis-server.service: Start request repeated too quickly.
May 27 09:30:33 cloud-us systemd[1]: redis-server.service: Failed with result 'exit-code'.
May 27 09:30:33 cloud-us systemd[1]: Failed to start Advanced key-value store.

Can anyone help me figure this out? I dont’ see any “Advanced key-value” in the redis.config file.

I googled the Error message, and it seems like it can be caused by a a multitude of different things. Maybe it is easier if you uninstall Redis completely and start over with a fresh install:

Remove Redis completely, including the config file:

apt purge redis-server
rm -rf /etc/redis
reboot

Reinstall Redis:

apt update && apt full-upgrade
apt install redis-server

Re-configure Redis:

cp /etc/redis/redis.conf /etc/redis/redis.conf.bak
sed -i "s/port 6379/port 0/" /etc/redis/redis.conf
sed -i s/\#\ unixsocket/\unixsocket/g /etc/redis/redis.conf
sed -i "s/unixsocketperm 700/unixsocketperm 770/" /etc/redis/redis.conf

In the following command you have to replace <secret> with the password from Nextcloud’s config.php:

sed -i "s/# requirepass foobared/requirepass <secret>/" /etc/redis/redis.conf
sed -i "s/# maxclients 10000/maxclients 10240/" /etc/redis/redis.conf
usermod -aG redis www-data
cp /etc/sysctl.conf /etc/sysctl.conf.bak
sed -i '$avm.overcommit_memory = 1' /etc/sysctl.conf
sysctl -p
systemctl restart redis-server

Hope that helps.

2 Likes

This was helpful to me, thank you.

I also had to install the php module for redis:

apt install php-redis

1 Like

Thank you!! :pray:

1 Like