Bobcares

Memcache In Nextcloud | Setup Tutorial

by | Nov 8, 2022

With Memcache, we can greatly increase Nextcloud server performance. At Bobcares, with our Server Management Services, we can handle your server issues.

Memcache In Nextcloud

The memory caching of Nextcloud is the process of storing frequently-requested objects in memory for faster retrieval.

A PHP opcode cache, also known as opcache, and data caching for the Web server are the two types of caches to use. On the Nextcloud admin page, we will see a warning if we don’t install and enable a local memcache. We are not required to use a memcache, and we are safe to ignore the warning.

In order to avoid having to compile PHP scripts again each time they are called, they are stored in a PHP opcache. Since PHP version 5.5, the Zend OPcache is included in the core, eliminating the need for manual installation. Redis, Memcached, or the user (APCu) can provide data caching.

We can choose any of the below memcache backends in Nextcloud considering our needs:

  1. Memcached
  2. APCu
  3. Redis
memcache in nextcloud

By installing and enabling the desired cache, and then adding the necessary entry to config.php, Memcaches must be explicitly configured in Nextcloud. Then we should run the PHP version and information to make sure the chosen memcache is operational after installing and enabling it.

How To Set Up Memcache In Nextcloud?

We recommend using APCu and Redis. We have to run the below steps to configure memcache in Nextcloud:

1. Firstly, we have to do APCu and Redis installation.

$ sudo apt install php-apcu redis-server php-redis

$ sudo service apache2 restart

2. Now modify the config file.

$ sudo nano /etc/redis/redis.conf

Press Ctrl+w and enter “port” to search for port 6379 and change port 0. Then press Ctrl+w to search for and uncomment unixsocket /var/run/redis/redis.sock. Now uncomment the below code and change the permissions to 770:

unixsocketperm 700 to unixsocketperm 770

Now press Ctrl+x, and the ‘Y’ to save and exit.

3. To the www-data group, add the Redis user redis:

$ sudo usermod -a -G redis www-data

4. We must restart Apache now:

$ sudo service apache2 restart

5. Also start the Redis server:

$ sudo service redis-server start

6. We must now include the caching configuration in the Nextcloud config file:

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

Add the below codes right after the last line and 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,
),

7. Press Ctrl+x, then ‘Y’ to save and exit.

8. To make sure Redis is set to launch at boot, use the below code:

$ sudo systemctl enable redis-server

Now there will not be a “Security & Setup Warning” about memcache not being enabled when we visit Nextcloud’s admin page.

[Are you looking for a response to another query? Click here to contact us.]

Conclusion

The article briefly explains the steps from our Tech team to install and configure memory cache/memcache in the Nextcloud.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

6 Comments

  1. RodmanB

    I cannot get this to work.

    Here is the config file:
    ‘oc6yiyqh1ppe’,
    ‘passwordsalt’ => ‘0MDWiWLY/jULucQJ7IsyrcS7uITM8v’,
    ‘secret’ => ‘zuunKSrSSMvEmx1Io0BJxV3by5vIoOaUjEZesrY2kxWsQ8/6’,
    ‘trusted_domains’ =>
    array (
    0 => ‘mycloud.devrod.com’,
    ),
    ‘datadirectory’ => ‘/nas/cloud/data’,
    ‘dbtype’ => ‘mysql’,
    ‘version’ => ‘25.0.1.1’,
    ‘overwrite.cli.url’ => ‘https://mycloud.devrod.com’,
    ‘dbname’ => ‘nextcloud’,
    ‘dbhost’ => ‘localhost’,
    ‘dbport’ => ”,
    ‘dbtableprefix’ => ‘oc_’,
    ‘mysql.utf8mb4’ => true,
    ‘dbuser’ => ‘nextcloud’,
    ‘dbpassword’ => ‘!ganRDy8D)’,
    ‘installed’ => true,
    ‘mail_smtpmode’ => ‘smtp’,
    ‘mail_smtpsecure’ => ‘tls’,
    ‘mail_sendmailmode’ => ‘smtp’,
    ‘mail_from_address’ => ‘rodmanlb’,
    ‘mail_domain’ => ‘hotmail.com’,
    ‘mail_smtpauthtype’ => ‘LOGIN’,
    ‘mail_smtphost’ => ‘smtp-mail.outlook.com’,
    ‘mail_smtpport’ => ‘587’,
    ‘mail_smtpauth’ => 1,
    ‘mail_smtpname’ => ‘rodmanlb@hotmail.com’,
    ‘mail_smtppassword’ => ‘7qU\\-S!boy7_7’,
    ‘default_phone_region’ => ‘US’,
    ‘memcache.local’ => ‘\\OC\\Memcache\\APCu’,
    ‘memcache.distributed’ => ‘\\OC\\Memcache\\Memcached’,
    ‘redis’ =>
    array (
    ‘host’ => ‘localhost’,
    ‘port’ => 0,
    ‘timeout’ => 0.0,
    ),

    );

    I have repeatedly and very deliberately followed the instructions. Prior to editing the config file as printed, the site works. Afterwards I get:
    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 server log.

    Upon reverting to the pre-edit, the site works,

    Reply
    • Hiba Razak

      Hi,
      Please contact our support team via live chat(click on the icon at right-bottom).

      Reply
  2. Farrukh Rehman

    Thanks, Work Perfectly with php8.0

    Reply
    • Hiba Razak

      Hi Farrukh,
      Thanks for the feedback.We are glad to know that our article helps you solves the issue ?

      Reply
  3. Lars K

    To my knowledge, it seems a ‘(‘ is missing somewhere? Im also getting Internal Server error after doing this.

    Add the below codes right after the last line and 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,
    ),

    —Where to put the missing “(“`?

    Reply
    • Lars K

      Sorry..I missread it and its working now..thank you.

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.