Project

General

Profile

Actions

Addressing Nextcloud Performance Warning - Configuring Memcache for Transactional File Locking

There are some warnings regarding your setup.
The database is used for transactional file locking. To enhance performance, please configure memcache, if available. See the documentation ↗ for more information.
Please double check the installation guides ↗, and check for any errors or warnings in the log.

The solution is to install Redis.


If you are using Ubuntu, the steps to install and configure Redis for Nextcloud may vary slightly. Here's how you can install and configure Redis on Ubuntu

Install the Redis server and PHP Redis extension:

sudo apt update
sudo apt install redis-server php-redis

Please read the next part carefully, to avoid server error.

Configure Redis:

Open the Redis configuration file using a text editor:

sudo nano /etc/redis/redis.conf

Find the line that starts with unixsocket and ensure it is uncommented. If it is already uncommented, you can skip this step. (I just Added it to the top of the file)

Unix sockets are generally faster than TCP/IP sockets.- https://lightningcr.com/projects/nextcloud/wiki/The_Performance_Advantages_of_Unix_Sockets_for_Interprocess_Communication_(IPC)

Add the following lines below unixsocket:

unixsocket /var/run/redis/redis.sock
unixsocketperm 600

NOTE: I have been seeing unixsocket /var/run/redis/redis-server.sock - you can use this, The naming of the Unix socket file itself (redis-server.sock or redis.sock) doesn't inherently make a difference in how Redis operates or functions. It's mostly a matter of convention or personal preference.

Save the changes and exit the text editor.

Execute the following command to navigate to the root directory:

cd /

Enable and start the Redis service:

sudo systemctl enable redis-server --now

Add the Apache user to the Redis group:

sudo usermod -aG redis www-data

Note: The Apache user may be different on some Ubuntu systems. Instead of www-data, it could be apache or http.

Configure Nextcloud to use Redis for caching and file locking:

Open the Nextcloud configuration file using a text editor. For example:

sudo nano /var/www/html/nextcloud/config/config.php

I have found that APCu is causing the Nextcloud instance to crash when using redis.sock, because of this I left it out of the 2nd config file and will use the

'memcache.local' found in this configration - https://lightningcr.com/projects/nextcloud/wiki/%22Configure_a_Memcache_for_Better_Performance_in_Nextcloud%22

They provide similar caching benefits as APCu but might be more stable in your specific environment.

If adding the following lines to the configuration file, remove the existing 'memcache.local' line:


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

If adding the following lines to the configuration file, do not remove the existing 'memcache.local' line:


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

If you are heaving problems there might be problem with the unixsocket: so you can remove that in the redis.conf by add a # by the settings and using the following setting in the next cloud config file, sudo nano /var/www/html/nextcloud/config/config.php

# unixsocket /var/run/redis/redis.sock
# unixsocketperm 700
'filelocking.enabled' => true,
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' => [
    'host' => '127.0.0.1',  // Replace with Redis server IP if necessary
    'port' => 6379,
    'timeout' => 0.0,
],

Save the changes and exit the text editor.

Restart the PHP-FPM service to apply the changes:
NOTE: I am using 8.1 so I had to use - sudo systemctl restart php8.1-fpm

sudo systemctl restart php8.1-fpm

restart the Apache service for the changes to take effect.

sudo systemctl restart apache2

That's it! Redis should now be installed and configured for Nextcloud on your Ubuntu system. Make sure to adapt the file paths and user names based on your specific setup.

Updated by Gareth Eaton 10 months ago · 23 revisions