Memcache - how to enable

Please help

My webhost says memcache is enable, but I sill get the error? How do i configure in nextcloud

There should be a link in the NC admin area pointing to the documentation here. Check out that link and scroll down to the “Memcached” section.

Note in particular the section showing lines you need to add to your config.php - make sure those lines are in your config.php, if not be sure to add them and re-check.

+1 for this answer. Worked like a charm. All directions in the link @zeugmatis posted.

  1. Ensure cache_module is installed
  2. Ensure the memcache is running (with ps)
  3. Edit the config.php

P.S. I changed the following

'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Memcached',
'memcached_servers' => array(
     array('localhost', 11211),
     array('server1.example.com', 11211),
     array('server2.example.com', 11211),
     ),

to:

'memcache.local' => '\OC\Memcache\Memcached',
'memcache.distributed' => '\OC\Memcache\Memcached',
'memcached_servers' => array(
     array('localhost', 11211),
     ),

I am not sure if its correct, but nextcloud works much faster and I can see quite a hit on the server memory afterwards.

Actually for nextcloud local caching APCu is recommended and seems to perform best. It should also work, if php-apcu module is installed.

As far as I understand from your config, your nextcloud is running and using only one server? In this case distributed memcache is useless, if I am not completely mistaken ;). So you can just remove 'memcache.distributed' line and 'memcached_servers' array completely from your config.php and things should run just the same.

As mentioned, ask your webhost for php apcu, and use 'memcache.local' => '\OC\Memcache\APCu', in case.

Next thing would be transactional file locking with redis: https://docs.nextcloud.com/server/10/admin_manual/configuration_server/caching_configuration.html#id4

If redis is installed and configured i.e. as this:

/etc/redis/redis.conf
port 0

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

you could use

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

to enable it for nextcloud.

@MichaIng Perfect answer.

Enabled APCu like this:

sudo apt-get install php5-apcu

Checked on the phpinfo page after a restart and the apcu seams to be enabled.
Modified config.php as you suggested, it all seams to be working fine (no errors at least).

Thanks

Okay, about local caching your nextcloud should use the preferred way now.

Ah, sorry about the web host guess, as it was TOs case, but not yours ;).

As mentioned, transactional file locking would be a further improvement:

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

Maybe php5-redis, not sure about the exact package name there.
And then the configuration as mentioned above.

Depends on which version of PHP your running and how you are running cron.

PHP7.0-apcu is disabled by default for the CLI.

So if you have cron enabled it will show errors there but run fine under normal php-mod-apache.

Not really sure why its disabled or if there is a fix yet.
On Debian Jessie with the PHP7 repos added I think it is as havent seen any error messages.

You can enable it for the CLI but you will have to google it.

conspacer is using php5, so there shouldn’t be a problem with that. But for php7.0 that is true. I solved it by

$ nano /etc/php/7.0/apache2/conf.d/20-apcu.ini
apc.enabled_cli=1

I was already asking myself why it is wanted disabled for cli. The PHP manual mentions it would be “not ideal to create, populate and destroy the APC cache on every CLI request” : http://php.net/manual/en/apcu.configuration.php#ini.apcu.enable-cli

Maybe someone could give an answer if this is also true for nextcloud or not ;).

Think you might have the wrong php folder there as surely it needs to be the CLI folder.
I can not remember if they are just sym links or seperate, think separate on Debian / Ubuntu.

But yeah, there must be a reason why apcu is disabled for CLI and creating it each time might outweigh any advantage.
Might be better just getting the complaints whilst disabled.
Guess with huge file stores it may be needed, but little info on the topic.

Actually I didn’t check my system where exactly I added that setting, maybe it was in some CLI subfolder. Just got that from my personal documentation, but sometimes I am too lazy to correct every step there ;). Will do that tomorrow. At least my nextcloud does not show the info log about missing cli cache anymore. Indeed it would be good to know if/in what case it is better that way.

€: Okay, I checked my system and actually added the setting to both files:
/etc/php/7.0/apache2/conf.d/20-apcu.ini AND
/etc/php/7.0/cli/conf.d/20-apcu.ini
No matter why :smiley:. I guess the second one has the desired influence and in the first one, the setting should not have some influence.

2 Likes