Project

General

Profile

Addressing Nextcloud Performance Warning - Configuring Memcache for Transactional File Locking » History » Revision 14

Revision 13 (Gareth Eaton, 07/11/2023 12:06 PM) → Revision 14/23 (Gareth Eaton, 07/11/2023 12:13 PM)

h1. 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. 

 --- 

 h3. 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: 


 <pre> 
 sudo apt update 
 sudo apt install redis-server php-redis 
 </pre> 

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

 Configure Redis: 

 Open the Redis configuration file using a text editor: 

 <pre> 
 sudo nano /etc/redis/redis.conf 
 </pre> 

 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) 

 Add the following lines below unixsocket: 
 <pre> 
 unixsocket /var/run/redis/redis.sock 
 unixsocketperm 600 700 
 </pre> 

 NOTE: I have been seeing *unixsocket /var/run/redis/redis-server.sock* 
 If this is the case with you the configuration file will be a little different. 

 Save the changes and exit the text editor. 
 Enable and start the Redis service: 

 <pre> 
 sudo systemctl enable redis-server --now 
 </pre> 

 Add the Apache user to the Redis group: 


 <pre> 
 sudo usermod -aG redis www-data 
 </pre> 

 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: 
 <pre> 

 sudo nano /var/www/html/nextcloud/config/config.php ( I use Chat GPT do do this part) 
 </pre> 

 h4. If you use the *unixsocket /var/run/redis/redis-server.sock* use the 2nd file not the 1st as this will cause it to crash 

 I have found that APCu is causing the Nextcloud instance to crash when using redis-server.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: 

 <pre> 

 '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, 
 ), 
 </pre> 

 --- 

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

 <pre> 

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


 --- 

 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 


 <pre> 
 # unixsocket /var/run/redis/redis.sock 
 # unixsocketperm 700 
 </pre> 

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


 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 


 <pre> 
 sudo systemctl restart php8.1-fpm 
 </pre> 

 restart the Apache service for the changes to take effect.  

 <pre> 
 sudo systemctl restart apache2 
 </pre> 


 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.