Really Struggling with REDIS Configuration

Nextcloud version (eg, 20.0.5): 25.0.0
Operating system and version (eg, Ubuntu 20.04): 22.04.1 LTS
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.54 (Unix)
PHP version (eg, 7.4): PHP 8.1.11

For the life of me, I cannot figure out how to set up NextCloud to leverage REDIS on my server.

I’m using DirectAdmin and I am running the REDIS plugin, which is working fine for all other websites which are leveraging it.

However, I just cannot figure out that config file and I’m not stupid… it just seems that there’s either information missing or implied that the information should be “obviousy”.

As per the documentation, I am adding the following lines into my config.php file:

'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,
],

and modifying it, to point to the right place and to remove the password, as there is none, therefore, looking like this:

'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => [
     'host'     => '/home/XXXXX/.redis/redis.sock',
     'port'     => 6379,
     'dbindex'  => 1,
     'timeout'  => 1.5,
],

I have changed the user folder for security.

Once saving this, the website simply says:

"'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 webserver log."

I have also looked at the config-sample.php but that’s just a huge massive mess of ridiculously over complicated text poorly formatted and sincerely time wasting.

I also added the following line on it’s own:

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

And received the same Internal Server Error message.

I’ve checked that REDIS is running:

root@srv1:~# ps ax | grep redis
    992 ?        Ssl    1:18 /usr/local/bin/redis-server unixsocket:/home/XXXXX/.redis/redis.sock
    999 ?        Ssl    0:17 /usr/local/bin/redis-server unixsocket:/home/2XXXXX2/.redis/redis.sock
  20609 pts/0    S+     0:00 grep --color=auto redis

I literally can’t get my head around this and would really need someone to provide some assistance… that or I just give up and remain frustrated by the fact that I cannot seem to figure this out and blame it entirely on the Documentation (which by the way isn’t even working for Version 25).

Web server error only shows when I add the configuration data below the last line, otherwise it won’t populate any error at all in the log.

The error I receive in the log is:

[Wed Oct 19 14:47:39.222908 2022] [proxy_fcgi:error] [pid 21300:tid 140467803493952] [client 109.103.199.70:0] AH01071: Got error 'PHP message: PHP Parse error: syntax error, unexpected token ",", expecting end of file in /home/XXXXX/domains/XXXXX.com/public_html/cloud/config/config.php on line 45'

If I place that same config data further up the file, nothing populates but I receive the same Internal Server Error.

I’m not familiar with DirectAdmin but usually with sockets it’s a permission issue. I note your Redis socket is in your home dir, this suggests redis is running under your username (usually considered a bad idea) and not the same user that is running your PHP.

If this is so:

  1. your PHP process won’t be able to even open the home dir.
  2. the PHP process won’t be able to write to the Redis socket.

Questions to check

  • What user is your PHP running as? Typically on ubuntu www-data
  • What user is Redis running as?
  • What permissions are set on the .sock file?
  • What permissions are set on the parent dir aka home/XXXXX/?
1 Like

PHP user is the user of the control panel user and it runs in the home folder, both for security reasons as well due to the limits on the number of DBs that REDIS can support.

DirectAdmin is effectively the same as cPanel, with each user having it’s own folder on a server and each service running independent from other users.

I checked the processes using HTOP and I can confirm that the same PHP user is running REDIS at that unix socket location specified in the “host” part.

Here’s a copy, minus the CPU / Memory info etc.
1889 XXXXX /usr/local/bin/redis-server unixsocket:/home/XXXXX/.redis/redis.sock

.SOCK file permission are: srwxrwx— 1 XXXXX XXXXX 0 Oct 19 13:17 redis.sock

Directory Permissions are 755 for the folder containing NextCloud.

XXXXX = Username

Would you be able to post your complete config? Remember to redact things like instanceid, passwordsalt, secret ect

Also you changed

     'dbindex'  => 0,

to

     'dbindex'  => 1,

any reason?

Edit: also the port should be set to 0 as well.

Reason for the index, is because NextCloud is running in a subfolder of the main domain.

The main domain is already leveraging REDIS, and if you don’t change the index, it will conflict.

Full Config:

<?php
$CONFIG = array (
  'instanceid' => 'XXXXXX',
  'passwordsalt' => 'XXXXXXXXXXX',
  'secret' => 'evLISOPdSs0LOYpEOh89XgqrlLeHcBGDPyes4Z5k/D0R+NEH',
  'trusted_domains' => 
  array (
    0 => 'XXXXX.com',
  ),
  'datadirectory' => '/home/XXXXX/domains/XXXXX.com/public_html/cloud/data',
  'dbtype' => 'mysql',
  'version' => '25.0.0.18',
  'overwrite.cli.url' => 'https://XXXXX.com/cloud',
  'dbname' => 'XXXXX',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'XXXXX',
  'dbpassword' => 'XXXXX',
  'installed' => true,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 0,
  'app_install_overwrite' => 
  array (
    0 => 'passwords',
    1 => 'side_menu',
    2 => 'drawio',
    3 => 'documentserver_community',
  ),
  'default_phone_region' => 'RO',
  'mail_from_address' => 'noreply',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'XXXXX.com',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpsecure' => 'tls',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.XXXXX.com',
  'mail_smtpport' => '587',
  'mail_smtpname' => 'contact@XXXXX.com',
  'mail_smtppassword' => 'XXXXX',
  'updater.secret' => '$2y$10$OyBSkNkYamDesYZA7j98Oun3fqsicSJ3qQiojaHPcPphewaV8sPTy',
);
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => [
     'host'     => '/home/XXXXX/.redis/redis.sock',
     'port'     => 6379,
     'dbindex'  => 1,
     'timeout'  => 1.5,
],

You may have missed my edit, but the port needs to be set to 0 not 6379. Just tested this on my own system. Also make sure you restart you php server in-between config changes. Caching can cause issues with changes not being picked up.

Tried doing as you suggested, however, even the documentation specifies that you should change the port?

Here’s my web server error:

[Wed Oct 19 15:28:12.508266 2022] [proxy_fcgi:error] [pid 21300:tid 140467837064768] [client 109.103.199.70:0] AH01071: Got error 'PHP message: PHP Parse error:  syntax error, unexpected token "=>" in /home/XXXXX/domains/XXXXX.com/public_html/cloud/config/config.php on line 46'
[Wed Oct 19 15:28:13.572571 2022] [proxy_fcgi:error] [pid 21299:tid 140468013311552] [client 109.103.199.70:0] AH01071: Got error 'PHP message: PHP Parse error:  syntax error, unexpected token "=>" in /home/XXXXX/domains/XXXXX.com/public_html/cloud/config/config.php on line 46'
[Wed Oct 19 15:28:20.496800 2022] [proxy_fcgi:error] [pid 21300:tid 140467786708544] [client 109.103.199.70:0] AH01071: Got error 'PHP message: PHP Parse error:  syntax error, unexpected token "=>" in /home/XXXXX/domains/XXXXX.com/public_html/cloud/config/config.php on line 46'
[Wed Oct 19 15:28:20.546912 2022] [proxy_fcgi:error] [pid 21299:tid 140468055275072] [client 109.103.199.70:0] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to a member function getRequest() on null in /home/XXXXX/domains/XXXXX.com/public_html/cloud/remote.php:53\nStack trace:\n#0 /home/XXXXX/domains/XXXXX.com/public_html/cloud/remote.php(171): handleException()\n#1 {main}\n  thrown in /home/XXXXX/domains/XXXXX.com/public_html/cloud/remote.php on line 53'
[Wed Oct 19 15:28:20.550347 2022] [proxy_fcgi:error] [pid 21300:tid 140467786708544] [client 109.103.199.70:0] AH01071: Got error 'PHP message: PHP Parse error:  syntax error, unexpected token "=>" in /home/XXXXX/domains/XXXXX.com/public_html/cloud/config/config.php on line 46'
[Wed Oct 19 15:28:21.163241 2022] [proxy_fcgi:error] [pid 21300:tid 140467786708544] [client 109.103.199.70:0] AH01071: Got error 'PHP message: PHP Parse error:  syntax error, unexpected token "=>" in /home/XXXXX/domains/XXXXX.com/public_html/cloud/config/config.php on line 46'
[Wed Oct 19 15:28:42.596474 2022] [proxy_fcgi:error] [pid 21299:tid 140468055275072] [client 109.103.199.70:0] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to a member function getRequest() on null in /home/XXXXX/domains/XXXXX.com/public_html/cloud/remote.php:53\nStack trace:\n#0 /home/XXXXX/domains/XXXXX.com/public_html/cloud/remote.php(171): handleException()\n#1 {main}\n  thrown in /home/XXXXX/domains/XXXXX.com/public_html/cloud/remote.php on line 53'

Config file now reads

… continued

‘updater.secret’ => ‘$2y$10$OyBSkNkYamDesYZA7j98Oun3fqsicSJ3qQiojaHPcPphewaV8sPTy’,
);
‘memcache.locking’ => ‘\OC\Memcache\Redis’,
‘memcache.local’ => ‘\OC\Memcache\APCu’,
‘memcache.distributed’ => ‘\OC\Memcache\Redis’,
‘redis’ => [
‘host’ => ‘/home/XXXXX/.redis/redis.sock’,
‘port’ => 0,
‘dbindex’ => 1,
‘timeout’ => 1.5,
],

Full server reboot.

Hi @alrnetwork

Put the ); on line 45 in your config.php to the very end of the file. This should solve the syntax errors.

Otherwise your latest redis config you posted here looks fine, at least as far as i can tell, based on the information in this thread so far

Didn’t work. This is ridiculous. Why isn’t this just a damn page within the configuration settings, just like it is for my other services?!

unexpected token “=>” in /home/XXXXX/domains/XXXXX.com/public_html/cloud/config/config.php on line 46’

It is complaining about a syntax error… What exactly is on line 46 of your config.php? Did you put the ); to the end of file, on it’s own line?

This is how it looks in my config.php.

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

Maybe you can try it with double back-slashes and curly brackets instead of square brackets…

As mentioned above …

in my case i had to add “www-data” as php / nginx user to the redis group by

usermod -a -G redis www-data

And also in my case i had to find out that redis socket was not “redis-server” but just “redis”

so maybe check /var/run/redis dir what is up to your case?!

may be you also have to set

‘host’ => ‘/var/run/redis/redis.sock’,

instead of
(‘host’ => ‘/var/run/redis/redis-server.sock’,)

if it is the case!!

Did you look at the error logs @alrnetwork posted? It’s clearly complaining about syntax errors in the config.php.

That’s all good information but doesn’t seem too be the issue here. At least it would not cause the error messages @alrnetwork posted. The Internal server error is almost certainly caused by Nextcloud not being able to process the config.php due to one or more syntax errors.

@alrnetwork In addition to my previous post, try also to go through your hole config.php line by line and make sure that all the arrays are properly closed and every single argument on every single line has the correct syntax and ends with a column. One missing column or bracket (or one too many) can make the difference between a working Nextcloud and an Internal Server Error. Also the hole config in itself is an array. That’s why the ); always has to be at the very end of the file.

If you can’t get it to work, please post the whole (current) config again (formated as a code block) and the current error logs.

OK so as @bb77 pointed out you have added the redis config outside the closing bracket. I missed that part. In your first post you said you only got errors in the log after you did that so I still think your first issue was the wrong port number.

  'mail_smtpname' => 'contact@XXXXX.com',
  'mail_smtppassword' => 'XXXXX',
  'updater.secret' => '$2y$10$OyBSkNkYamDesYZA7j98Oun3fqsicSJ3qQiojaHPcPphewaV8sPTy',
// This is your current issue delete or comment out ); 
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => [
     'host'     => '/home/XXXXX/.redis/redis.sock',
     'port'     => 0, // I belive this was the inital issue
     'dbindex'  => 1,
     'timeout'  => 1.5,
],
); // This belongs here

Remember the config.php is php code so it must be syntax correct.

1 Like

It’s probably a combination of both. :wink: But wrong port or path would cause different error messages:

Wrong port for example would cause something like this:

Got error 'PHP message: PHP Warning:  Redis::pconnect(): php_network_getaddresses: getaddrinfo for /var/run/redis/redis-server.sock failed...

I think the best way to go is to get rid of all the syntax errors first and then go from there…

1 Like

So it turns out, it’s because APCu was not installed in DirectAdmin. Followed the guide here: PHP Extensions | Directadmin Docs

No more fatal errors. I was then able to configure accordingly.

2 Likes