Cloud Services / Open Source / Storage

Install Cache-Enhanced Nextcloud Cloud Storage on the Ubuntu Linux Server

24 Dec 2020 6:00am, by

At a time when more and more people and businesses are having to shift the way they work, the on-premises collaboration-friendly Nextcloud “cloud” storage service provides an easy to use, reliable, and extensible (with hundreds of available apps to install) option. Think of it as a Google Drive or Dropbox shared file drive on your (virtual) Linux computer, but built with open source. And with every new iteration, the developers add new features and refine what’s already there.

The latest release of Nextcloud, 20, includes some important changes, two of which are the new Dashboard — for a quick overview of what’s happening on your Nextcloud instance — and Talk integrations, so you can bridge your local chat tool with services like IRC, Slack, MS Teams, and more.

In other words, if you’ve yet to hop on board the Nextcloud bandwagon, now’s a very good time.

I want to walk you through the installation of Nextcloud 20. I’ll be demonstrating on Ubuntu Server 20, so you’ll need to have an instance of the open source server platform up and running.

I’m also going to show you how to improve the performance of Nextcloud, by integrating caching into the mix (otherwise, Nextcloud can seem a bit slow).

With that said, let’s get to work.

Install the Necessary Dependencies

The first thing we’ll do is install the necessary dependencies. Log into your Ubuntu Server instance and take care of the web server and database with the command:

sudo apt-get install apache2 mysql-server -y

Now we’ll install PHP and a few other remaining dependencies with the command:

sudo apt-getinstall php zip libapache2-mod-php php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip php-mysql php-bcmath php-gmp -y

Take Care of the Database

Next, we’ll take care of the database. First, we must secure MySQL with the command:

sudo mysql_secure_installation

You’ll want to first set an admin password and then answer yes (by typing “y”) for the remaining questions.

After securing the database installation, you can now create the database and a new user. Log into the mysql console with the command:

sudo mysql

At the MySQL prompt, create the new database with the command:

CREATE DATABASE nextcloud;

Create the new Nextcloud database user with the command:

CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'PASSWORD';

Where PASSWORD is a unique and strong password.

Grant the new user the proper permissions for the database with the command:

GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';

Finally, flush the MySQL privileges and exit the console with the commands:

FLUSH PRIVILEGES;exit

Download, Unpack and Locate Nextcloud

We’ll now download the Nextcloud file. Change into the tmp directory with the command:

cd /tmp

Download the Nextcloud file with the command:

wget https://download.nextcloud.com/server/releases/nextcloud-20.0.2.zip

Unpack the zip file with the command:

unzip nextcloud-20.0.2.zip

If you find the unzip command isn’t present, install it with:

sudo apt-get install zip -y

Once the file is decompressed, relocate it to the web server document root with the command:

sudo mv nextcloud /var/www/html/

Change the ownership of the nextcloud directory, such that the web server has access, with the command:

sudo chown -R www-data:www-data /var/www/html/nextcloud

Configure Apache for Nextcloud

In order for Apache to know about Nextcloud, we must create a configuration file. Create the file with the command:

sudo nano /etc/apache2/sites-available/nextcloud.conf

Paste the following into the new file:

Save and close the file.

Enable the new configuration with the command:

sudo a2ensite nextcloud

Next, enable the necessary Apache modules with the command:

sudo a2enmod rewrite headers env dir mime

Configure the PHP memory limit for Nextcloud with the command:

sudo sed -i '/^memory_limit =/s/=.*/= 512M/' /etc/php/7.4/apache2/php.ini

Restart Apache with the command:

sudo systemctl restart apache2

Complete the Installation via the Web Installer

You can now connect to Nextcloud to finish up the installation. Open a web browser and point it to http://SERVER/nextcloud (Where SERVER is the IP address or domain of the hosting server). In the resulting page (Figure 1), create a new admin user and fill out the information for your database.

 

Figure 1. The final step of the Nextcloud installation.

Make sure the checkbox for Install recommended apps is checked and click Finish setup. Give the installer time to complete the process. When the installation finishes, you’ll find yourself at the new Nextcloud Dashboard (Figure 2), where you can start configuring your new on-premise cloud server to perfectly meet your needs.

 

Figure 2: The new Nextcloud Dashboard is configured on a per-user basis.

Enable Caching for Better Performance

For our next trick, we’re going to enable caching, which will drastically reduce load times for Nextcloud objects and pages.  The first step is to install Redis, memcached, and the PHP apcu module. Do this with the command (run on the same machine hosting Nextcloud):

sudo apt-get install redis-server php-memcached memcached php-apcu -y 

When that installation completes, start and enable the Redis server and memcached with the commands:

sudo systemctl start redis-server

sudo systemctl enable redis-server

sudo systemctl start memcached

sudo systemctl enable memcached

With Redis installed, we need to tweak the configuration file. Open that file with the command:

sudo nano /etc/redis/redis.conf

In that file, you’ll want to edit the lines below with the following changes (you will have to remove the # character from the second two lines):

In order for Redis to be able to function with the web server, it must be added to the proper group with the command:

sudo usermod -aG redis www-data

The next step is to configure Nextcloud to make use of the Redis server. Open the Nextcloud configuration file for editing with command:

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

Paste the following above the final line in the file:

The bottom section of that configuration should look like:

Save and close the file.

Restart Apache with the command:

sudo systemctl restart apache2

We next must tweak PHP to use Opcache, which will improve basic functionality. Open the php.ini file with the command:

sudo nano /etc/php/7.X/apache2/php.ini

Where X is the release of PHP found on your server.

Starting around line 1769, you’ll need to make the following changes to the following lines (removing any leading ; characters):

Save and close the file.

Restart Apache with the command:

sudo systemctl restart apache2

Head back to your browser and reload Nextcloud. Although you won’t notice the speed increase at first, eventually (once the cache has been sufficiently populated) the speeds will improve.

And that’s how you install Nextcloud 20 on Ubuntu Server 20.04 and give it a bit of a performance bump with caching. With this cloud platform up and running, you are empowered to do so much more, without having to rely on the third-party hosts to house your files and other personal or business-related documents.

The New Stack is a wholly owned subsidiary of Insight Partners. TNS owner Insight Partners is an investor in the following companies: Bit.

A newsletter digest of the week’s most important stories & analyses.