# Memcache - how to enable

**URL:** <https://help.nextcloud.com/t/memcache-how-to-enable/2651>\
**Category:** ℹ️ Support\
**Created:** [August 26, 2016, 3:17pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651 "2016-08-26T15:17:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![terencefaul](https://help.nextcloud.com/letter_avatar/terencefaul/32/5_5575768a8748004e209b776fc1b2916d.png) [@terencefaul](https://help.nextcloud.com/u/terencefaul)\
**Post date:** [August 26, 2016, 3:17pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/1 "2016-08-26T15:17:11Z")

</div>

Please help

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

---

<div class="post-metadata">

**Author:** ![zeugmatis](https://help.nextcloud.com/letter_avatar/zeugmatis/32/5_5575768a8748004e209b776fc1b2916d.png) [@zeugmatis](https://help.nextcloud.com/u/zeugmatis)\
**Post date:** [August 27, 2016, 5:35pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/2 "2016-08-27T17:35:01Z")

</div>

There should be a link in the NC admin area pointing to the [documentation here](https://docs.nextcloud.com/server/10/admin_manual/configuration_server/caching_configuration.html). 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.

---

<div class="post-metadata">

**Author:** ![conspacer](https://help.nextcloud.com/user_avatar/help.nextcloud.com/conspacer/32/2800_2.png) [@conspacer](https://help.nextcloud.com/u/conspacer)\
**Post date:** [February 5, 2017, 4:19pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/3 "2017-02-05T16:19:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MichaIng](https://help.nextcloud.com/user_avatar/help.nextcloud.com/michaing/32/2125_2.png) [@MichaIng](https://help.nextcloud.com/u/MichaIng)\
**Post date:** [February 5, 2017, 4:35pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/4 "2017-02-05T16:35:19Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![conspacer](https://help.nextcloud.com/user_avatar/help.nextcloud.com/conspacer/32/2800_2.png) [@conspacer](https://help.nextcloud.com/u/conspacer)\
**Post date:** [February 5, 2017, 6:07pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/5 "2017-02-05T18:07:38Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![MichaIng](https://help.nextcloud.com/user_avatar/help.nextcloud.com/michaing/32/2125_2.png) [@MichaIng](https://help.nextcloud.com/u/MichaIng)\
**Post date:** [February 5, 2017, 6:40pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/6 "2017-02-05T18:40:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stuart\_Naylor](https://help.nextcloud.com/user_avatar/help.nextcloud.com/stuart_naylor/32/2359_2.png) [@Stuart\_Naylor](https://help.nextcloud.com/u/Stuart_Naylor)\
**Post date:** [February 5, 2017, 9:51pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/7 "2017-02-05T21:51:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MichaIng](https://help.nextcloud.com/user_avatar/help.nextcloud.com/michaing/32/2125_2.png) [@MichaIng](https://help.nextcloud.com/u/MichaIng)\
**Post date:** [February 6, 2017, 1:32am UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/8 "2017-02-06T01:32:20Z")

</div>

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](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 ;).

---

<div class="post-metadata">

**Author:** ![Stuart\_Naylor](https://help.nextcloud.com/user_avatar/help.nextcloud.com/stuart_naylor/32/2359_2.png) [@Stuart\_Naylor](https://help.nextcloud.com/u/Stuart_Naylor)\
**Post date:** [February 6, 2017, 1:56am UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/9 "2017-02-06T01:56:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MichaIng](https://help.nextcloud.com/user_avatar/help.nextcloud.com/michaing/32/2125_2.png) [@MichaIng](https://help.nextcloud.com/u/MichaIng)\
**Post date:** [February 6, 2017, 2:26am UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/10 "2017-02-06T02:26:06Z")

</div>

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 😃. I guess the second one has the desired influence and in the first one, the setting should not have some influence.

---

<div class="post-metadata">

**Author:** ![tflidd](https://help.nextcloud.com/letter_avatar/tflidd/32/5_5575768a8748004e209b776fc1b2916d.png) [@tflidd](https://help.nextcloud.com/u/tflidd)\
**Post date:** [March 27, 2017, 8:07pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/11 "2017-03-27T20:07:27Z")

</div>



---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 4, 2024, 3:33pm UTC](https://help.nextcloud.com/t/memcache-how-to-enable/2651/12 "2024-12-04T15:33:59Z")

</div>


