Installing NextCloud on Ubuntu 16.04 LTS with Apache2, Lets Encrypt, Redis and APCu


NextCloud is an open source fork of ownCloud that has gone completely FOSS (Free and Open-Source Software), the significant difference being ownCloud is closed source with two pricing models, wheras NextCloud is open source. The NextCloud developers value their users.

I recommend hosting this on a VPS with more than 100GB’s of storage or a dedicated server since the whole point of NextCloud is to be like Dropbox and save your files the more storage the better while the minimum storage requirement is 20GB.

NextCloud Requirements:

  • 1Ghz CPU
  • 1GB Ram
  • 20GB HDD

Even though a 20GB disk would be enough to install NextCloud on it’s not recommended due to the limited storage space for files. It is also recommended to keep backups of your server in the event of a failure. Most hosts will keep backups of the node, but will not be liable if you lose any data.

If you are looking for a reasonably priced VPS take a look at RamNode, they offer a great performance to dollar ratio.

high performance ssd vps

Preparing the Server

For the purpose of this guide it’s best to install a fresh Ubuntu 16.04 LTS server (Minimal or Full) x64.

Since brand new installations are based on images, it’s best to update the server before any work has been done so that all packages are the most recent.

apt update && apt upgrade

Once the fetch has been completed hit the enter button to accept the upgrades and continue the installation.

Create a user account so that you can log in as a non-root user. Assign sudoers to your new account also.

adduser newuser sudo

Installing Nextcloud Dependencies

Time to install the basic LAMP stack! This command will install apache2, mysql, php7 and several modules that makes sure the three servers can collaborate between each other. When you are prompted to continue, press enter.

sudo apt install lamp-server^

During the installation MySQL will ask to set a root password. I suggest you use a random password generator site to generate a password and save it in a password manager. Tap enter when you have entered your desired password.

Nextcloud will also need some more dependencies so let’s install them now. Confirm the packages and press enter.

sudo apt install php-apcu redis-server php-redis && sudo apt install php-zip php-dompdf php-xml php-mbstring php-gd php-curl

This will install APCu, Redis, and the required PHP modules. Now it’s time to enable a few Apache modules required for configuration:

sudo a2enmod rewrite headers env dir mime

Restart Apache

sudo service apache2 restart

Navigate to http://your-server-ip and verify that the page is working.

Installing Let’s Encrypt

Let’s Encrypt is a certificate authority which “hands out” free SSL certificates, the only catch is that they need to be renewed frequently but I will cover how to set-up auto renewal in this guide.

sudo apt install letsencrypt python-letsencrypt-apache

Now lets create the certificate

sudo letsencrypt --apache --agree-tos --email your-email-address -d

When going through the Let’s Encrypt setup wizard choose the Secure option.

Now when you navigate to your site you will be greeted with a green confirmation in your URL bar confirming that SSL is enabled.

While we are configuring Apache, let’s edit the le-config and add a line at the bottom of the file right after the SSLCertificateKeyFile line:

<IfModule mod_headers.c>
     Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"

Reload Apache

sudo systemctl reload apache2

Installing NextCloud

Your webroot default directory is set too /var/www/html lets cd to /var/www and rm -rf html

Download the latest version of NextCloud from their official site.

sudo wget

Unpack the archive with the command.

sudo tar -xvjf nextcloud-10.0.0.tar.bz2

Now let’s rename the nextcloud folder to www.

sudo mv nextcloud www

Change the permissions so Apache can read and write to the folder.

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

Creating MySQL Database

You can either give nextcloud your root MySQL password and it can create the databases for you or you can use this section to create your own databases if you do not feel comfortable giving nextcloud your root MySQL information.
Open a root MySQL session.

mysql -U root -p

Let’s create a database and a user for NextCloud. (Replace database name, username and password with your own information of your choice).

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

Exit the MySQL session with:


Tuning NextCloud

Once you have navigated back to your NextCloud ui and put in the database information, let’s move on to finishing the setup and tuning the URL’s.

1. Enabling .htaccess

sudo nano /etc/apache2/apache2.conf

Use Ctrl+W and paste the first line in below to jump to the correct section.

        Options Indexes FollowSymLinks


        Require all granted

Restart Apache.

sudo service apache2 restart

2. Configure Redis
Confirm that Redis is set to start on boot:

sudo systemctl enable redis

Open the next cloud configuration file:

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

Add the following lines above the );

'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
     'host' => 'localhost',
     'port' => 6379,

3. Making the URL look cleaner
Go to your nextcloud root folder.

 cd /var/www/html

Open the NextCloud config file:

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

Add the following to the end of the file below an existing line:

'htaccess.RewriteBase' => '/',

Update the .htaccess:

sudo -u www-data php occ maintenance:update:htaccess



That pretty much wraps up how to install NextCloud on an Ubuntu Server. If you have any further questions please leave a comment below and I will do my best to help you out.

About the author


  • what are you supposed to enter for sudo letsencrypt –apache –agree-tos –email your-email-address -d

    I get the email part, but I dont have a domain name….I am installing this as my server, it makes no sense. I entered the IP address of my server computer but that didn’t work….i then left it as it was and it seemed to finish installing lets encrypt, but of course a bunch of errors about the server

  • Hi! thank you for this tutorial 🙂

    I have a problem with:
    While we are configuring Apache, let’s edit the le-config and add a line at the bottom of the file right after the SSLCertificateKeyFile line:

    Header always set Strict-Transport-Security “max-age=15768000; includeSubDomains; preload”

    where do I find that config file?
    Thank you in advance! 🙂

    yours, Markus

By Nick

Recent Posts