Can't access nextcloud after setting up redis

Support intro

posted this on “installation” section, didn’t notice a support section until now
i’m new to nextcloud. Almost done setting up a fresh nextcloud 21 until i reached redis.

I followed this guide for my nextcloud installation

for the redis setup, i initially followed this guide, but realized my nextcloud installation guide also have a redis section, so I undo everything i did (except the permission), and went back to the redis section in my first nextcloud installation guide.

thank you for the help. I’m extremely puzzled…

Nextcloud version (eg, 20.0.5): 21.0.2
Operating system and version (eg, Ubuntu 20.04): ubuntu 21.04
Apache or nginx version (eg, Apache 2.4.25): nginx 1.18
PHP version (eg, 7.4): 7.4 (I do have other versions installed)

The issue you are facing:
after setting up redis, my nextcloud server suddenly has a error message:

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.

Is this the first time you’ve seen this error? (Y/N):
yes

Steps to replicate it:

  1. setup nextcloud normally using this guide until you reaches Redis setup.

  2. open the Redis configuration file at /etc/redis/redis.conf use command sudo nano /etc/redis/redis.conf

  3. change port 6379 to port 0, uncommentunixsocket /var/run/redis/redis.sock and unixsocketperm 700 then change unixsocketperm 700to unixsocketperm 770

  4. save and quit, then add the user www-data to the redis group by using the command: ’ sudo usermod -a -G redis www-data

  5. After this i realized i’m using nginx instead of Apache, so i went back to my original guide for redis setup. and undo everything i did except the permission.

  6. Comment unixsocket /var/run/redis/redis.sock and unixsocketperm 770

  7. change port 0 to port 6379

  8. using the original guide i used NC installation. edit nextCloud configuration file by using command “sudo nano /usr/share/nginx/nextcloud/config/config.php”

  9. add the following code to the ending ); line.

'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
     'host' => 'localhost',
     'port' => 6379,
     ),
  1. Save and close the file. Then restart Nginx and PHP-FPM using command “sudo systemctl restart nginx php7.4-fpm”

  2. now go back to the NC webpage, a the internal error is there.

The output of your Nextcloud error.log

2021/06/10 18:33:30 [crit] 192871#192871: *3372 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 35.203.252.150, server: 0.0.0.0:443

2021/06/10 18:38:02 [crit] 192871#192871: *3460 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 35.203.252.118, server: 0.0.0.0:443

2021/06/10 20:03:43 [error] 193335#193335: *5006 access forbidden by rule, client: 45.146.165.123, server: raid1.duckdns.org, request: "GET /console/ HTTP/1.1", host: "207.38.189.168:443"

2021/06/10 20:12:35 [error] 203863#203863: *5136 access forbidden by rule, client: 192.168.1.1, server: raid1.duckdns.org, request: "GET /.well-known/webfinger HTTP/2.0", host: "raid1.duckdns.org"

2021/06/10 20:12:35 [error] 203863#203863: *5136 access forbidden by rule, client: 192.168.1.1, server: raid1.duckdns.org, request: "GET /.well-known/nodeinfo HTTP/2.0", host: "raid1.duckdns.org"

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'redacted',
  'passwordsalt' => 'redacted',
  'secret' => 'redacted',
  'trusted_domains' =>
  array (
    0 => 'redacted',
  ),
  'datadirectory' => '/mnt/raid1/nextcloud-data/',
  'dbtype' => 'mysql',
  'version' => '21.0.2.1',
  'overwrite.cli.url' => 'redacted',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'redacted',
  'dbpassword' => 'redacted',
  'installed' => true,

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

The output of your Apache/nginx/system log in /var/log/____:

nothing in there. is there a way to check error history? or is everything just in one log

What i’v tried

  • add an extra \ to the redis config
  • double check on my ufw firewall setting regarding port 6379
  • double check on my portfowarding on router regarding port 6379
  • uninstall and reinstall of redis-server
3 Likes

Point 3 might be your problem. You’re not running redis on port 6379 but as socket. So your config file should be the following.

‘redis’ =>
array (
‘host’ => ‘/var/run/redis/redis.sock’,
‘port’ => 0,
),’

I undo everything i did, see point 5,6,7

Try the following.

Check through CLI whether the Redis server is up and is accepting connections to its socket on port 6379 (assuming for all the below that you have no password set):

sudo redis-cli -h 127.0.0.1 -p 6379
shows:
redis 127.0.0.1:6379>

Type: ping
The answer should be: PONG

Leave Redis-console by typing: quit

If Redis doesn’t give you the “Pong” something is wrong with your redis-configuration.

If you get back that “PONG” make sure you have in NC’s config:

--------------- 8< ---------------

  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
    'timeout' => 0,
    'dbindex' => 0,
  ),

--------------- >8 ---------------

Now:
sudo chown -R redis.www-data /var/run/redis

And finally:
Restart the Redis server.

Does it work now?

Hi @notmike

If you run redis on the same server as your nextcloud there is really no need to run it on a dedicated port and open that port to the whole world.

Remove redis including the config files

apt purge redis-server

Install packages again

apt install redis-server php7.4-redis

Configure Redis

Backup the Redis configuration file:

cp /etc/redis/redis.conf /etc/redis/redis.conf.bak

Adjust the configuration:

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
sed -i "s/# maxclients 10000/maxclients 512/" /etc/redis/redis.conf
usermod -aG redis www-data

Configure it in the config.php

'redis' => 
array (
'host' => '/var/run/redis/redis-server.sock',
'port' => 0,
'timeout' => 0.0,
),

It is working like this on my instance like a charm for years. Alltough I have to say that I use apcu for local memchache. My config in the config.php looks like this…

'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',

…but I see no reason why it should not work with

'memcache.local' => '\OC\Memcache\Redis',
3 Likes

@Tamsy
It does not work

I followed what you instructed:
it answered: PONG

changed my redi config in nginx:

‘memcache.distributed’ => ‘\OC\Memcache\Redis’,
‘memcache.local’ => ‘\OC\Memcache\Redis’,
‘memcache.locking’ => ‘\OC\Memcache\Redis’,
‘redis’ => array(
‘host’ => ‘localhost’,
‘port’ => 6379,
‘timeout’ => 0,
‘dbindex’ => 0,
),

executed sudo chown -R redis.www-data /var/run/redis
restarted redis server via command 'sudo systemctl restart redis-server

the error persists.

Thank you @bb77 this fixed it!

1 Like

This has been solved, I appreciate everyone’s help!

Battling to get Redis working on Centos 7 with Nginx. I’ll keep going! This post is two years old but gives some kind of indication about what one needs to do.

I re-open this thread because i’ve tried your solution but it still not work. Internal server error when loading the NC page.

Here is my config.php :

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

When i comment that part in the config file then i can access again to my interface.

i’m on debian 11 with NC 27.

thanks in advance for your help

Not sure why it doesn’t work for you, but here’s a few things you could check…

  • Check if the Redis server installed and the Redis service is running:

    systemctl status redis.service
    
  • Check if the appropriate PHP module is installed and enabled?

    apt list php*-redis
    
    php --ri redis
    
  • Check the config file /etc/redis/redis.conf, especially the following lines:

    bind 127.0.0.1 ::1
    port 0
    unixsocketperm 770
    unixsocket /var/run/redis/redis-server.sock
    

    If unsure post your config here, you can use the follwing command to print only the uncommented lines:

    cat /etc/redis/redis.conf | grep -v '^$\|^#'
    
  • Check if the www-data user is in the redis group

    groups www-data
    

it’s active, running and enabled.


the one with [installed] at the end of the line is this one :

  • php8.1-redis/bullseye,now 6.0.1-1+0~20231006.53+debian11~1.gbpe91da2 amd64

redis

Redis Support => enabled
Redis Version => 6.0.1
Redis Sentinel Version => 1.0
Available serializers => php, json, igbinary
Available compression => lzf, zstd, lz4

Directive => Local Value => Master Value
redis.arrays.algorithm => no value => no value
redis.arrays.auth => no value => no value
redis.arrays.autorehash => 0 => 0
redis.arrays.connecttimeout => 0 => 0
redis.arrays.distributor => no value => no value
redis.arrays.functions => no value => no value
redis.arrays.hosts => no value => no value
redis.arrays.index => 0 => 0
redis.arrays.lazyconnect => 0 => 0
redis.arrays.names => no value => no value
redis.arrays.pconnect => 0 => 0
redis.arrays.previous => no value => no value
redis.arrays.readtimeout => 0 => 0
redis.arrays.retryinterval => 0 => 0
redis.arrays.consistent => 0 => 0
redis.clusters.cache_slots => 0 => 0
redis.clusters.auth => no value => no value
redis.clusters.persistent => 0 => 0
redis.clusters.read_timeout => 0 => 0
redis.clusters.seeds => no value => no value
redis.clusters.timeout => 0 => 0
redis.pconnect.pooling_enabled => 1 => 1
redis.pconnect.connection_limit => 0 => 0
redis.pconnect.echo_check_liveness => 1 => 1
redis.pconnect.pool_detect_dirty => 0 => 0
redis.pconnect.pool_poll_timeout => 0 => 0
redis.pconnect.pool_pattern => no value => no value
redis.session.locking_enabled => 0 => 0
redis.session.lock_expire => 0 => 0
redis.session.lock_retries => 100 => 100
redis.session.lock_wait_time => 20000 => 20000
redis.session.early_refresh => 0 => 0


bind 127.0.0.1 ::1
protected-mode yes
port 0
tcp-backlog 511
unixsocket /var/run/redis/redis-server.sock
unixsocketperm 770
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis/redis-server.pid
loglevel notice
logfile /var/log/redis/redis-server.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /var/lib/redis
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
maxclients 512
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
oom-score-adj no
oom-score-adj-values 0 200 800
appendonly no
appendfilename “appendonly.aof”
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events “”
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes


i’ve checked and it is in the redis group.

Thanks for your help

Any help ?

Can you share a few log entries from your nextcloud.log from the period when you saw 500 errors?

Sorry for the late reply, I compared your config and the php-redis package with my test server and everything seems to be identical. The only difference is that I have PHP 8.2 installed. In this context, you could check whether the active PHP version on your system and the php-redis package are on the same version.

Another reason for the internal server error could be some app that is not compatible with Redis. However, I can’t think of any specific app that is known for this, so I’m not sure.

Other than that, I’m running out of ideas, sorry…

So really weird behaviour just happened…

I went back to my config.php to uncomment the lines regarding redis to then check the logs.
The few lines were gone, not even commented, just gone.
So i put them again (without the #) to load the 500 error.
But when i came back to my instance, i could access it and no more message regarding redis in administration panel.
Really weird.
So i guess my problem is solved.
Thanks guys for the help :slight_smile:

2 Likes

@grosJambon33000 @bb77 I’m on a similar system and am getting an Internal Server error when activating Redis for ‘memcache.distributed’. My config file:

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

Furthermore I get the following errors in the admin log:

[PHP] Error: RedisException: No such file or directory at /var/www/nextcloud/lib/private/RedisFactory.php#137

PUT /ocs/v2.php/apps/user_status/api/v1/heartbeat?format=json
from 185.65.135.192 by Linus at 2023-11-06T21:57:17+00:00

RedisException: No such file or directory
RedisException: Redis server went away
...

I can also add that I’m migrating from a ncp instance to a manual installation. Any ideas why Redis would be crashing for some user_status api call?

Try to replace 'host' => '/var/run/redis/redis.sock', with:

'host' => '/var/run/redis/redis-server.sock',

…in your config.php.

If it still doesn’t work please double check everything I posted here.

2 Likes

Thanks @bb77! That was the solution to my problem. :+1:

2 Likes

Hello,

I recently setup a new NC instance, this is my fifth instance in two years and this is the first time I’ve ever seen this error occur.

I am using the following:
Server: Ubuntu 22.04.3
NC version: 28.0.1
Apache2: 2.4.52
PHP version: 8.1.2

Whenever I uncomment 'memcache.distributed' => '\OC\Memcache\Redis',, I get the exact same error as the OP. I have followed everything in post 5 and in post 11 and I still get the same error. As soon as I comment it out again, access is restored.

Within my logs, I see the following odd errors that I’ve never seen before.

PHP error RedisException: No such file or directory at /var/www/nextcloud/lib/private/RedisFactory.php#117
and
Index error RedisException No such file or directory
and
Core error RedisException No such file or directory Exception thrown: RedisException
and
Core error RedisException Redis server went away Exception thrown: RedisException

All above errors always occur in unison.

I’m trying to get this setup for a small business owner that wanted it done before the holidays, so any and all help and recommendations are greatly appreciated.

Cheers.