iMarket Digital Properties

0 %
iMarket Digital Properties Ltd
Design · Develop · Monetize · Support
  • Location:
    United Kingdom
  • City:
    London
  • Service Area:
    Global
Business Systems
Business Services
24/7 Support
Websites
Web Applications
E-commerce Solutions
Digital Platforms
Products & Services
Public & Private Networks

Configuring Memory Caching In Nextcloud

January 4, 2018
 1. Install APCu and Redis:
$ sudo apt install php-apcu redis-server php-redis

$ sudo service apache2 restart
2. Edit the configuration file
$ sudo nano /etc/redis/redis.conf
Ctrl+w and enter “port” to search for and change:
port 6379
to
port 0
Then Ctrl+w to search for and uncomment:
unixsocket /var/run/redis/redis.sock
and uncomment the line below and change the permissions to 770:
unixsocketperm 700
to
unixsocketperm 770
Ctrl+x, the ‘Y’ to save and exit.3. Add the Redis user redis to the www-data group:
$ sudo usermod -a -G redis www-data
4. Restart Apache:
$ sudo service apache2 restart
5. Start Redis server:
$ sudo service redis-server start
6. Add the caching configuration to the Nextcloud config file:
$ sudo nano /var/www/html/nextcloud/config/config.php
Add the following right after the last line and before the ‘);’ (before the last parenthesis and semicolon)
'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Memcached',
'redis' => 
array (
'host' => 'localhost',
'port' => 0,
'timeout' => 0.0,
),
Ctrl+x, then ‘Y’ to save and exit.NOTE: If you are getting and Internal Server Error with the config above, please see the UPDATED comments belowhttps://kenfavors.com/code/configuring-memory-caching-in-nextcloud/#comment-8355To verify Redis is enabled to start on boot:
$ sudo systemctl enable redis-server
Now when you go to the admin page in Nextcloud, there should no longer be a ‘Security & Setup Warning’ about memory caching not being enabled.Also see How To Install Memcached to install Memcached if only using APCu

REFERENCES

https://docs.nextcloud.com/server/18/admin_manual/configuration_server/caching_configuration.html https://bayton.org/docs/nextcloud/installing-nextcloud-on-ubuntu-16-04-lts-with-redis-apcu-ssl-apache/

Hosting

This web app has been tested on DigitalOcean. This app can also be installed using other hosts such as Amazon AWS, Google Cloud, Microsoft Azure, Vultr and others.

Installation & Maintenance

If you would like to get this app installed, maintained or need training, Contact Me to get current rates.
Posted in TutorialsTags:
19 Comments
  • Renzo

    Hello,
    sorry for the trouble, I have a difficulty: I followed step by step your directions, Nextcloud tells me that everything is fine with regard to the memcache, but I can not upload new files or create new ones. Where am I wrong?
    Thanks so much!

    Renzo

    8:58 am September 24, 2018 Reply
    • Somehow I think I have come across this problem in Nextcloud before but I can’t remember how I resolved it (& I didn’t write it down). But it sounds like the first place to start is your user permissions on the server. I would make sure that you chown the nextcloud and data directory, example:

      $ sudo chown -R www-data:www-data /var/www/html/nextcloud/

      and chmod the data directory, example:

      $ sudo chmod -R 0770 /var/www/html/nextcloud/data

      and finally if that doesn’t work, you can try to add your user permissions to nextcloud, example:

      $ sudo setfacl -R -m "u:user:rwx" /var/www/html/data/user

      where the first user is your server username and the second is your username in Nextcloud. If any of this helps or you find the solution, could you kindly post it? Thanks

      3:57 pm September 24, 2018 Reply
  • Marco

    DON’T FOLLOW THIS TUTORIAL. AFTER IS IT IMPOSSIBILE TO UPLOAD FILE ON NEXTCLOUD.

    7:19 pm March 9, 2019 Reply
    • Hello, since Renzo above first posted this issue I have not had the same problem. I did do 2 changes in Nextcloud’s config file above which works perfectly, changing

      'memcache.local' => 'OCMemcacheAPCu',

      to

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

      and adding:

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

      However, this still may not solve your issue. This same issue has also been posted on Jason Bayton’s forum and seems only to affect very few people. Why? I couldn’t tell you because again, I have never had this problem. The issue is further discuseed here – https://discuss.bayton.org/t/installing-nextcloud-on-ubuntu-16-04-lts-with-redis-apcu-ssl-apache/62/39 and further down the thread here – https://discuss.bayton.org/t/installing-nextcloud-on-ubuntu-16-04-lts-with-redis-apcu-ssl-apache/62/51 – but it seems that it was not solved. It appears Renzo was seeking answers and Jason Bayton, who was attempting to solve the issue, could only finally state:

      At this point without seeing your environment first hand I’m not sure what’s wrong, sorry.
      You could maybe swap redis for aPCU in your config.php file and see if that resolves the black page, but that doesn’t fix redis itself.

      So, in summary, I think this is a rare and isolated issue that has something to do with one’s operating environment and not with the code (unless changing the config lines above have any affect). And again, for anyone that has this issue and has found a solution, please post it!

      10:29 am March 11, 2019 Reply
  • athma

    i had to manually edit the path, form the configuration file.
    unixsocket /var/run/redis/redis-server.sock

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

    that worked for me .!!

    4:08 pm October 7, 2019 Reply
  • LapinMalin

    missing backslashes in line ‘memcache.local
    host doesn’t work, replaced by localhost
    otherwise works fine on raspbian

    ‘memcache.local’ => ‘\OC\Memcache\Redis’,
    ‘memcache.distributed’ => ‘\OC\Memcache\Redis’,
    ‘memcache.locking’ => ‘\OC\Memcache\Redis’,
    ‘filelocking.enabled’ => ‘true’,
    ‘redis’ =>
    array (
    ‘host’ => ‘localhost’,
    ‘port’ => 0,
    ‘timeout’ => 0.0,
    ),

    5:02 pm June 14, 2020 Reply
    • Thank you for catching the backslashes in memcache.local – the post has been Updated!
      It’s been a while since I’ve reviewed my config file, I also have ‘host’ => ‘localhost’, – the post has been Updated.

      12:55 pm June 15, 2020 Reply
  • markus

    I followed the instructions to set up memory caching with redis.
    After all i get a Internal Server Error when trying to get a nextcloud session.
    Pi4, RPi OS Buster 64, Postgresql, apache2

    8:31 pm October 13, 2021 Reply
    • I recently had the same Internal Server Error for what appears to be no reason at all (server update? new codebase?)… my new config settings are below:

      I changed the lines:

      'memcache.local' => '\OC\Memcache\Redis',
      'memcache.distributed' => '\OC\Memcache\Redis',
      'memcache.locking' => '\OC\Memcache\Redis',
      'filelocking.enabled' => 'true',
      'redis' => 
      array (
        'host' => 'localhost',
        'port' => 0,
        'timeout' => 0.0,
      ),
      

      to (working config):

      'memcache.local' => '\OC\Memcache\APCu',
      'memcache.distributed' => '\OC\Memcache\Memcached',
      'redis' =>
       array (
         'host' => 'localhost',
         'port' => 0,
         'timeout' => 0.0,
      ),
      

      I had to eliminate the lines

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

      and

      'filelocking.enabled' => 'true',

      and change the caching from Redis to APCu and Memcached for the other two lines. Hope this helps.

      6:58 am October 14, 2021 Reply
      • markus

        Thx Ken

        I’m actually running APCu and wanted to switch to Redis. Didn’t get it working yet. Maybe keeping APCu.

        10:14 pm October 14, 2021 Reply
        • I have been bumping into this. Does anyone know what changed? The only thing I am having difficulty configuring is memory caching.

          4:35 pm January 16, 2022 Reply
  • Following this tutorial for the latest Nextcloud version returns:

    “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.”

    In order to get your server up and running you have to remove the modifications from the nextcloud config.php file.

    10:57 pm January 3, 2022 Reply
    • I have never seen the error message to “remove the modifications from the nextcloud config.php file” so I am not sure what this could be unless you posted the full config.php file or you check the webserver log.

      9:28 am January 7, 2022 Reply
      • Michael Eberle

        I’m getting the same error. Removing the modifications to the config.php file will allow the nextcloud page to come up, but I still get the ‘no memcache has been configured’ message on the settings page.

        6:00 am April 20, 2022 Reply
  • Steve J

    Switched from APCU to Redis.
    Now all uploads are 3 times slower… isn’t it supposed to be the opposite???

    11:27 am February 20, 2022 Reply
  • Zylence

    The code examples above did not work out for me, the one from the official docs did:
    https://docs.nextcloud.com/server/22/admin_manual/configuration_server/caching_configuration.html

    ‘memcache.local’ => ‘OCMemcacheAPCu’,
    ‘memcache.locking’ => ‘OCMemcacheRedis’,
    ‘memcache.distributed’ => ‘OCMemcacheRedis’,
    ‘redis’ => [
    ‘host’ => ‘/run/redis/redis-server.sock’,
    ‘port’ => 0,
    ‘dbindex’ => 0,
    ‘timeout’ => 1.5,
    ]

    6:07 pm March 2, 2022 Reply
  • Abbas Rezaei

    hi,
    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’ => ‘OCMemcacheAPCu’,
    ‘memcache.locking’ => ‘OCMemcacheRedis’,
    …but I see no reason why it should not work with

    ‘memcache.local’ => ‘OCMemcacheRedis’,

    9:42 am April 12, 2022 Reply
Write a comment