Where are you using WebAssembly?
Wasm promises to let developers build once and run anywhere. Are you using it yet?
At work, for production apps
At work, but not for production apps
I don’t use WebAssembly but expect to when the technology matures
I have no plans to use WebAssembly
No plans and I get mad whenever I see the buzzword
Cloud Services / Storage

Performance Tune Nextcloud with Caching

Oct 1st, 2019 1:28pm by
Featued image for: Performance Tune Nextcloud with Caching
Feature image by Clara Sander from Pixabay.

Nextcloud has become one of the most widely-used on-premises cloud solutions on the planet. There’s a reason for that. This cloud software is not only open source, but it’s also scalable, extendible, and reliable. But for larger companies, looking to get as much performance as possible, Nextcloud might need a bit of tweaking out of the box. Why? Because by default Nextcloud does not enable caching.

Why would you need caching? As you probably already know, caching increases performance by storing frequently-requested objects in memory. By doing this the retrieval of those objects is considerably faster. Since we’re talking about the cloud, you could have hundreds (even thousands) of users hitting that server simultaneously. Without caching enabled, that server is going to take a significant hit as each user retrieves objects.

Fortunately, with Nextcloud, enabling caching isn’t all that challenging. It’s not as simple as clicking a checkbox in the Settings, but you can add this feature without having to jump through too many hoops.

Let’s do just that. We’ll enable caching on Nextcloud 16, running on the Ubuntu Server 18.04 platform, to help make your Nextcloud server run like a champ.

What You’ll Need

Obviously, you’ll need a running instance of Ubuntu Server. I will also assume you’ve already installed Nextcloud. If not, check out “How to Install Nextcloud 16 on Ubuntu Server 18.04”. You will also need a user with sudo privileges. That’s it. You’re ready to tune Nextcloud.

Installing Redis

Before you can configure Nextcloud caching, you must first install a caching service. We’ll use the in-memory data structure store, Redis (as Redis is also open source, scalable, and integrates well with Nextcloud).

To install Redis, log into your Nextcloud server, open a terminal (if your server has a GUI), and issue the command:

This should install without issue. Once the installation completes, start and enable Redis with the following two commands:

Configure Redis

With Redis installed, it must now be configured. Open the config file with the command:

Edit the following lines to reflect these changes:

Save and close the configuration file.

Before we jump into the Nextcloud configuration, we must also add the redis user to the www-data group. Without doing this, Nextcloud will fail. To add the redis user to the group, issue the command:

That’s it for the Redis configuration.

Configure Nextcloud

We now have to configure Nextcloud to make use of our newly-added Redis service. To do that, open the Nextcloud configuration with the command:

Scroll down to the bottom of that file. The last two lines should be:

Above those two lines, paste the following:

The configuration should now look similar to that shown in Figure 1, below.

Figure 1: The Redis configuration added to Nextcloud.

Save and close the file. Finally, restart Apache with the command:

And that’s all there is to enable caching with Redis for Nextcloud.

Enable Opcache

You can also enable opcache in the php.ini file — a recommended configuration, by Nextcloud, to improve basic functionality. Without opcache enabled, you will probably see a warning when you log in as the Nextcloud admin user. To enable PHP opcache, you must configure the php.ini file. First, you’ll need to find out the latest version of PHP installed on your server. To locate the most recent version of PHP issue the command:

You should see directories with all the installed versions (Figure 2).

Figure 2: Versions 5.6 to 7.3 are installed.

If PHP 7.3 is the most recent version installed, the command to open the configuration file would be:

Within that file, make sure the following lines reflect the changes below (the configuration options begin around line 1799):

Once you’ve made the changes, save and close the file. To make the changes take effect, restart Apache with the command:

Install and Enable PHP APCu

We can configure PHP APCu to handle the local cache, alongside Redis controlling the file locking cache. NOTE: Only do this if your server has the memory overhead to do so.

To install PHP APCu, issue the command:

After the installation completes, open the Nextcloud configuration again with the command:

In that file, change this line:


Save and close the file. Restart Apache with the command:

At this point, your users should start seeing significant improvement in the performance of the Nextcloud server, all thanks to a bit of caching. Of course, due to the nature of caching, users might not experience this improvement immediately. However, over time they should notice Nextcloud responding much more efficiently.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Enable.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.