Struggling with redis caching

Hi there, I am dealing with my first every NextCloud install and working may through my little issues one by one. However, I don’t seem to be able to get readis caching to work.

I installed Redis and configured redis according to the many tutorials I have read up to now. From my point of view redis seems to work:

$ cat /etc/redis.conf | grep unixsocket
unixsocket /var/run/redis/redis.sock
unixsocketperm 700
$ ls -la /run/redis
total 0
drwxr-xr-x  2 redis redis  60 Feb  9 21:29 .
drwxr-xr-x 19 root  root  560 Feb  9 21:49 ..
srwx------  1 redis redis   0 Feb  9 21:29 redis.sock

systemctl status redis
...
Feb 09 21:29:17 homeserver redis-server[3176]: 3176:M 09 Feb 2020 21:29:17.806 # Server initialized
Feb 09 21:29:17 homeserver redis-server[3176]: 3176:M 09 Feb 2020 21:29:17.806 # WARNING     overcommit_memory is set to 0! Background save may fail under low memory co>
Feb 09 21:29:17 homeserver redis-server[3176]: 3176:M 09 Feb 2020 21:29:17.806 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This >
Feb 09 21:29:17 homeserver redis-server[3176]: 3176:M 09 Feb 2020 21:29:17.806 * DB loaded from disk: 0.000 seconds
Feb 09 21:29:17 homeserver redis-server[3176]: 3176:M 09 Feb 2020 21:29:17.806 * The server is now ready to accept connections at /var/run/redis/redis.sock

I added the redis section to /etc/webapps/nextcloud/config/config.php like this:

'mail_smtpauthtype' => 'LOGIN',
'mail_smtpauth' => 1,
'mail_smtphost' => 'w0057ba2.kasserver.com',
'mail_smtpport' => '587',
'mail_smtpsecure' => 'tls',
'maintenance' => false,
'preview_max_x' => '2048',
'preview_max_y' => '2048',
'jpeg_quality' => '60',
//  'memcache.local' => '\\OC\\Memcache\\Redis',
'filelocking.enabled' => 'true',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' =>
array (
'host' => '/var/run/redis/redis.sock',
'port' => 0,
'timeout' => 0,
'password' => '',
'dbindex' => 0,),
);

However, the moment I remove the comments from ‘//memcache.local’ my NextCloud system will become inaccessible and only shows this error:

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.

Can anyone spot something which I did wrong, or anything else to check?

I am running Nextcloud 18.0.0 on Arch Linux with nginx as webserver.

You’ve restricted access to the Redis socket to the owner (redis) only. How should Nexcloud be able to access it with this setting?

First I would recommend to set “unixsocketperm 0770”, second you need to add the web server user (Is it www-data?), to the additional redis group so that the user is allowed to access the socket. See here and search for " additional_groups":

https://wiki.archlinux.org/index.php/users_and_groups

Great! Thanks for getting back j-ed.
Didn’t realise that socketperm 700 relates to filesystem permissions, well, and I forgot to mention that I did add http, which is my equivalent to www-data, to the redis group:

$ groups http
redis http

So I went ahead and changed socketperm to 0770 and restarted redis and nginx

cat /etc/redis.conf | grep unixsocket
unixsocket /var/run/redis/redis.sock
unixsocketperm 0770

Unfortunately didn’t help, tried to reboot as well.
Given that this might be related to access rights I thought I’d just give full access to test:

$ sudo chmod 777 /run/redis/redis.sock
$ ls -la /run/redis
total 0
drwxr-xr-x 2 redis redis 60 Feb 11 16:48 .
drwxr-xr-x 19 root root 560 Feb 11 16:48 …
srwxrwxrwx 1 redis redis 0 Feb 11 16:48 redis.sock

Didn’t help, changed the permissions in redis.conf from 0770 to 0777 and can see the settings get applied after restarting the redis service but I am still stuck with the error message.

Edit: Thought I’d better make sure that indeed NextCloud is using http as user, I think it is?

$ ps -ef | grep http
http 552 521 0 16:48 ? 00:00:00 php-fpm: pool www
http 553 521 0 16:48 ? 00:00:00 php-fpm: pool www
http 2414 2413 0 16:51 ? 00:00:00 nginx: worker process
http 2415 2413 0 16:51 ? 00:00:00 nginx: cache manager process

You can check if the web server user “http” is allowed to access Redis by executing the following commands:

# sudo -u http redis-cli --verbose -s /var/run/redis.sock info

BTW, I would remove the password line from the nextcloud configuration if you’re not using a password.

Just tried, looks like things are ok:

$ sudo -u http redis-cli --verbose -s /var/run/redis/redis.sock info

Server

redis_version:5.0.7
redis_git_sha1:00000000
redis_git_dirty:0

But my redis.sock is in a subdir called redis, instead of /var/run. Not sure if it matters though?

‘password’ => ’ ’ is gone now.

Sorry, /var/run was a copy/paste error from my system. Ok, then I cannot see any reason why Nextcloud should use the configured service for its locking mechanism. What is the exact error now if you try to start Nextcloud?

The error will show immediately, even without restarting anything like nginx or redis.
The moment I enable memcache.local I can do a refresh in my browser and will get this message in my browser:

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.

Comment out the offending line, save, browser refresh, and the portal is back online again.

Not sure which log it’s referring to, but there is nothing in journalctl.

Here is my redis setup if it can help you.

/usr/bin/redis-server 127.0.0.1:6379

Config.php in Nextcloud

  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
  ),

Looks like your config.php lacks port and host for redis

1 Like

Redis should primarily be used for locking. You should use APCu for local caching. Check-out the admin guide for further details:

https://docs.nextcloud.com/server/18/admin_manual/configuration_server/caching_configuration.html?highlight=cache#id2

That`s how I have configured my server. I think setting-up a distributed cache is not required for a standard installation:

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

That would be an alternative to using Sockets I guess? I will try this and see if it makes a difference.

I’ll try this as well.

‘memcache.local’ => ‘OC\Memcache\APCu’, behaves identical to Redis.
The moment it’s there I’ll get the error, delete that line and I am back online.
I did make sure I have APCu installed:

yay php-apcu
extra/php-apcu 5.1.18-2 (52.1 KiB 183.6 KiB) (Installed)
A userland caching module for PHP

This got me thinking if maybe I have multiple version of PHP and somehow the wrong one is used for NextCloud?
But I get the same version no matter if running with my standard user or http

sudo -su http php --version
PHP 7.4.2 (cli) (built: Jan 21 2020 18:16:58) ( NTS )
Copyright © The PHP Group
Zend Engine v3.4.0, Copyright © Zend Technologies
with Zend OPcache v7.4.2, Copyright ©, by Zend Technologies

As far as switching from Sockets to ports is concerned, I changed to port 6379 in /etc/redis.conf:

Redis 5.0.7 (00000000/0) 64 bit
Running in standalone mode
Port: 6379
PID: 637291

And changed the config.php accordingly, but running into php errors. I need to investigate this some more, probably a settings mismatch between php-fpm, redis.conf and config.php…
Running out of time for now, I will update this thread once I had the chance to look into this in more detail.

You should check the availability of the modules using the web browser first, although it is worse to check the cli too.

Not sure how I would check the modules with the web browser?
And which ones do I need to check?

Sorry for the dump response, but I only know php from using it, never had to troubleshoot so far…

For the web component, create e.g. an info.php file on your web server which contains the following code and open it with a browser:

<?php phpinfo() ?>

For the cli component run the following command:

php -m

The relevant modules are:

  • APCu -> Zend OPcache
  • Redis -> redis
2 Likes

php -m: Zend OPcache is there but no redis module!

$ pacman -Q | grep php
php 7.4.2-1
php-apcu 5.1.18-2
php-fpm 7.4.2-1
php-gd 7.4.2-1
php-igbinary 3.1.2-1
php-imagick 3.4.4-5
php-intl 7.4.2-1
php-pgsql 7.4.2-1
php-redis 5.1.1-3

Means, redis php is installed but not enabled. This looks like this may also be the reason for another issue, the NextCloud console kept on complaining about a missing imagick module which is equally installed but not showing in php -m.
This may be it…I’ll get back to you…
Searching for how to enable these modules as we speak :slight_smile:

Edit: Bingo! That was it, had to go through quite a few config files and un-comment stuff. And this time round I also had to restart the php-fpm service. Have to say this is quite complex, lots of moving parts which themselves have dependencies…but we got there in the end.
By the way, this did indeed solve my imagick issue as well :slight_smile:

Thanks a lot for your help!

2 Likes