Every time I log into my Nextcloud server as the administrator, the overview tab shows me a warning about memcache. It also provides a link where you can read about it and learn what to do about this warning. One key thing that I noted was that it is not required, per their administrator manual:

You can significantly improve your Nextcloud server performance with memory caching, where frequently-requested objects are stored in memory for faster retrieval. There are two types of caches to use: a PHP opcode cache, which is commonly called opcache, and data caching for your Web server. If you do not install and enable a local memcache you will see a warning on your Nextcloud admin page. A memcache is not required and you may safely ignore the warning if you prefer.


That said, I like the idea of improving performance, and I also like to learn new things. To be honest, I’ve never set up memory caching for a web server before, so this was a great opportunity to learn something new. Granted, in the past I’ve set up caching for compiling, such as ccache for compiling Android, so I figured it would be along that line of thought.

So, a quick perusal of the instructions offered 3 different suggested methods: Redis, memcached, and APCu. After reviewing the instructions, the Nextcloud environment did not recommend memcached, and Redis looked like more work than setting up APCu, so I went with APCu instead. A quick search revealed it was already in the Ubuntu repository:

$ sudo aptitude search php-apcu
[sudo] password for alaskalinuxuser: 
p   php-apcu                        - APC User Cache for PHP                    
p   php-apcu-bc                     - APCu Backwards Compatibility Module 

And so I installed it, and restarted my apache server:

$ sudo apt install php-apcu
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
The following NEW packages will be installed:
  php-apcu php-apcu-bc
0 upgraded, 2 newly installed, 0 to remove and 21 not upgraded.
Need to get 50.7 kB of archives.
After this operation, 236 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 php-apcu amd64 5.1.18+4.0.11-1build1 [41.8 kB]
Processing triggers for libapache2-mod-php7.4 (7.4.3-4ubuntu2.4) ...
alaskalinuxuser@alaskalinuxuser-PowerEdge-R520:~$ sudo systemctl restart apache2

Then I edited my Nextcloud config.php file, and added this line:

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

Note, I added it above some other lines, so I needed the comma. Supposedly, all I had to do now was refresh my admin overview tab and the problem would be solved, which it was! I was greeted with the green check mark of all is well. But, further reading in the instructions for setting APCu up in Nextcloud said that I *may* run into problems with my Nextcloud cron job, because APCu is disabled from running in the CLI unless I made provision for that. Fortunately for me, they provided ample instructions, and all I had to do was add this block to my /etc/php/7.4/apache/php.ini file:

; Just added for APCu to ensure no issues with cron.

All told, this was a great learning experience that took less than 30 minutes!

Linux – keep it simple.

Leave a Reply

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