Redis Unix Socket PHP7.4-FPM NC 24.0.3

When configured according to documentation a Redis unix socket with NC 24.03 throws internal server error:
https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/caching_configuration.html
https://docs.nextcloud.com/server/stable/admin_manual/configuration_files/files_locking_transactional.html?highlight=redis

All troubleshooting related to this prior thread on Redis Unix Socket (php8.0) attempted:

1.) The redis socket exists:

# ls -lh /var/run/redis
total 4.0K
-rw-rw---- 1 redis redis 5 Jul 30 16:47 redis-server.pid
srwxrwxr-x 1 redis redis 0 Jul 30 16:47 redis.sock

2.) php-redis module has been enabled:

$ php --ri redis

redis

Redis Support => enabled
Redis Version => 5.3.7
Redis Sentinel Version => 0.1
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 => 10 => 10
redis.session.lock_wait_time => 2000 => 2000

3.) nextcloud/config/config.php contains:

  'memcache.local' => '\OC\Memcache\Redis',
  'memcache.distributed' => '\OCMemcache\Redis',
  'filelocking.enabled' => true,
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,  <----  I have verified that redis is running on port 0
    'timeout' => 1.5,
    'password' => 'secret',  <--- I have verified that the password is correct
  ),

4.) redis unix socket is running:

# ps aux | grep redis
redis       6468  0.2  0.6  74768 26428 ?        Ssl  16:47   0:01 /usr/bin/redis-server 127.0.0.1:0
root        7384  0.0  0.0   6432   656 pts/1    S+   16:58   0:00 grep --color=auto redis

5.) redis is a member of www-data group

# members www-data
www-data redis

and

# stat /var/run/redis/redis.sock 
  File: /var/run/redis/redis.sock
  Size: 0         	Blocks: 0          IO Block: 4096   socket
Device: 18h/24d	Inode: 838         Links: 1
Access: (0775/srwxrwxr-x)  Uid: (  127/   redis)   Gid: (  135/   redis)
Access: 2022-07-30 17:17:37.227272165 +0800
Modify: 2022-07-30 17:17:36.343272193 +0800
Change: 2022-07-30 17:19:13.279269161 +0800
 Birth: -

6.) tail -f ncerrors/error.log reveals no errors :upside_down_face:

NC installation profile:
Ubuntu Server 20.04, LAMP, ModSec disabled

please adviseā€¦

thanks

I almost got the same configuration, the only difference is in config.php.

I configured
ā€˜memcache.localā€™ => ā€˜\OC\Memcache\APCuā€™,

and i am missing:
ā€˜memcache.distributedā€™ => ā€˜\OCMemcache\Redisā€™,

Everything works here ā€¦ perhaps you want to switch the caching to apcu and use redis only for file locking ā€¦

Try to changeā€¦

'host' => '/var/run/redis/redis.sock' 

to

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

in config.php.

Btw, in order to connect to the Redis CLI, the following command should work:

redis-cli -s /var/run/redis/redis-server.sock

@bb77

thanksā€¦ just figured this out.

redis-cli -s /var/run/redis/redis-server.sock ā† works as root, but not as my user running nextcloud (permission denied)

trying to sort that out now. I run Virtualmin

No luckā€¦ I added my user to the redis group and rebooted.

I can successfully connect to redis as my user, but I still get internal server error

FYI, changing redis.sock to redis-server.sock had no effect. I now able to connect to redis as server user and as rootā€¦ but I still get internal server error.

Your user, the one you log in to your Ubuntu instance, doesnā€™t need access. Only www-data does.

Is the php-redis module installed on your server?

Other than that Iā€™m running out of ideas. I have the exact same config on my server, except that I didnā€™t set a password in Redis. Maybe you could try disabling the authentification. Since you are using Unix sockets and therfore Redis is not exposed on the network anyways, I donā€™t think that you gain much security if you enable authentication.

Progressā€¦ bug identified?

Now that my user can properly connect to redisā€¦ I went back tried variations of @abyss02 suggestions and I finally get something other than internal server error

my config/config.php now has:

 'memcache.local' => '\OC\Memcache\Redis',
//  'memcache.distributed' => '\OCMemcache\APCu',  <-- Redis nor APCu will work
  'filelocking.enabled' => true,
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => array (
    'host' => '/var/run/redis/redis-server.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),

My NC is now working, but there seems to be a bug in 'memcache.distributed' as neither Reds, nor APCu values will work.

I get a nice, noticeable, speed boost. Any thoughts on the bug?

1 Like

These are my installed modules:

[PHP Modules]
apc
apcu
bcmath
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
imagick
imap
intl
json
ldap
libxml
mbstring
memcache
memcached
msgpack
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
pspell
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
ssh2
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
uploadprogress
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

As root, I also ran phpenmod apcu & phpenmod redis. Either value used with ā€˜memcache.distributedā€™ results in internal server error

AFAIK only Redis or Memcached can be used as a distributed cache:

'memcache.distributed' => '\\OC\\Memcache\\Redis',

Also Iā€™m not sure if you gain anything with a distributed cache on a single node. Nonetheless I added the above line on my instance for testing purposes and it did work. But normaly I use only APCu for local memcache and Redis for file locking:

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

Edit: PHP modules look fine. Not sure why ā€˜memcache.distributedā€™ => ā€˜\OC\Memcache\Redisā€™, throws an internal server error on your instance.

@bb77 I will heed your adviecā€¦ everything seems to be working super, super fast minus the ā€˜memcache.distributedā€™ . I canā€™t remember the exact details but a few months ago APCu caused me headaches, so I have been looking to fully eliminate it. My config above minus distributed cache will be my final solution.

Thanks. I appreciate your help with this.

1 Like