// Tutorial //

How To Install and Configure Nextcloud on Ubuntu 16.04

Published on November 1, 2016 · Updated on October 6, 2017
Default avatar
By Michael Lenardson
Developer and author at DigitalOcean.
How To Install and Configure Nextcloud on Ubuntu 16.04
Not using Ubuntu 16.04?Choose a different version or distribution.
Ubuntu 16.04

Introduction

Nextcloud, a fork of ownCloud, is a file sharing server that permits you to store your personal content, like documents and pictures, in a centralized location, much like Dropbox. The difference with Nextcloud is that all of its features are open-source. It also returns the control and security of your sensitive data back to you, thus eliminating the use of a third-party cloud hosting service.

In this tutorial, we will install and configure a Nextcloud instance on an Ubuntu 16.04 server.

Note: The Nextcloud project has matured significantly since this article was initially written. The content here has been updated to reflect the more recent recommended installation procedures as of October, 2017. Older comments may not be directly relevant to the current set of instructions.

Prerequisites

In order to complete the steps in this guide, you will need the following:

  • A sudo user and firewall configured on your server: You can create a user with sudo privileges and set up a basic firewall by following the Ubuntu 16.04 initial server setup guide.
  • (Optional) A domain name pointed to your server: We will be securing connections to the Nextcloud installation with TLS/SSL. Nextcloud can set up and manage a free, trusted SSL certificate from Let’s Encrypt if your server has a domain name. If not, Nextcloud can set up a self-signed SSL certificate that can encrypt connections, but won’t be trusted by default in web browsers. If you are using DigitalOcean, you can follow our guide on how to set up a domain name for your server if you intend to use Let’s Encrypt.

Once you have completed the above steps, continue on to learn how to set up Nextcloud on your server.

Step 1 – Installing Nextcloud

We will be installing Nextcloud using the snappy packaging system. This packaging system, available on Ubuntu 16.04 by default, allows organizations to ship software, along with all associated dependencies and configuration, in a self-contained unit with automatic updates. This means that instead of installing and configuring a web and database server and then configuring the Nextcloud app to run on it, we can install the snap package which handles the underlying systems automatically.

To download the Nextcloud snap package and install it on the system, type:

  1. sudo snap install nextcloud

The Nextcloud package will be downloaded and installed on your server. You can confirm that the installation process was successful by listing the changes associated with the snap:

  1. snap changes nextcloud
Output
ID Status Spawn Ready Summary 2 Done 2017-10-03T20:03:09Z 2017-10-03T20:03:26Z Install "nextcloud" snap

The status and summary indicate that the installation was completed without any problems.

Getting Additional Information About the Nextcloud Snap

If you’d like some more information about the Nextcloud snap, there are a few commands that can be helpful.

The snap info command can show you the description, the Nextcloud management commands available, as well as the installed version and the snap channel being tracked:

  1. snap info nextcloud

Snaps can define interfaces they support, which consist of a slot and plug that, when hooked together, gives the snap access to certain capabilities or levels of access. For instance, snaps that need to act as a network client must have the network interface. To see what snap “interfaces” this snap defines, type:

  1. snap interfaces nextcloud
Output
Slot Plug :network nextcloud :network-bind nextcloud - nextcloud:removable-media

To learn about all of the specific services and apps that this snap provides, you can take a look at the snap definition file by typing:

  1. cat /snap/nextcloud/current/meta/snap.yaml

This will allow you to see the individual components included within the snap, if you need help with debugging.

Configuring an Administrative Account

There are a few different ways you can configure the Nextcloud snap. In this guide, rather than creating an administrative user through the web interface, we will create one on the command line in order to avoid a small window where the administrator registration page would be accessible to anyone visiting your server’s IP address or domain name.

To configure Nextcloud with a new administrator account, use the nextcloud.manual-install command. You must pass in a username and a password as arguments:

  1. sudo nextcloud.manual-install sammy password

The following message indicates that Nextcloud has been configured correctly. The first few lines are present because the PCNTL extension is not included with the Nextcloud snap. These can be safely ignored:

Output
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php Nextcloud is not installed - only a limited number of commands are available Nextcloud was successfully installed

Now that Nextcloud is installed, we need to adjust the trusted domains so that Nextcloud will respond to requests using the server’s domain name or IP address.

Adjusting the Trusted Domains

When installing from the command line, Nextcloud restricts the host names that the instance will respond to. By default, the service only responds to requests made to the “localhost” hostname. We will be accessing Nextcloud through the server’s domain name or IP address, so we’ll need to adjust this setting to accept these type of requests.

You can view the current settings by querying the value of the trusted_domains array:

  1. sudo nextcloud.occ config:system:get trusted_domains
Output
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php localhost

Currently, only localhost is present as the first value in the array. We can add an entry for our server’s domain name or IP address by typing:

  1. sudo nextcloud.occ config:system:set trusted_domains 1 --value=example.com
Output
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php System config value trusted_domains => 1 set to string example.com

If we query the trusted domains again, we will see that we now have two entries:

  1. sudo nextcloud.occ config:system:get trusted_domains
Output
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php localhost example.com

If you need to add another way of accessing the Nextcloud instance, you can add additional domains or addresses by rerunning the config:system:set command with an incremented index number (the “1” in the first command) and adjusting the --value.

Securing the Nextcloud Web Interface with SSL

Before we begin using Nextcloud, we need to secure the web interface.

If you have a domain name associated with your Nextcloud server, the Nextcloud snap can help you obtain and configure a trusted SSL certificate from Let’s Encrypt. If your Nextcloud server does not have a domain name, Nextcloud can configure a self-signed certificate which will encrypt your web traffic but won’t be able to verify the identity of your server.

With that in mind, follow the section below that matches your scenario.

Option 1: Setting Up SSL with Let’s Encrypt

If you have a domain name associated with your Nextcloud server, the best option for securing your web interface is to obtain a Let’s Encrypt SSL certificate.

Start by opening the ports in the firewall that Let’s Encrypt uses to validate domain ownership. This will make your Nextcloud login page publicly accessible, but since we already have an administrator account configured, no one will be able to hijack the installation:

  1. sudo ufw allow 80,443/tcp

Next, request a Let’s Encrypt certificate by typing:

  1. sudo nextcloud.enable-https lets-encrypt

You will first be asked whether your server meets the conditions necessary to request a certificate from the Let’s Encrypt service:

Output
In order for Let's Encrypt to verify that you actually own the domain(s) for which you're requesting a certificate, there are a number of requirements of which you need to be aware: 1. In order to register with the Let's Encrypt ACME server, you must agree to the currently-in-effect Subscriber Agreement located here: https://letsencrypt.org/repository/ By continuing to use this tool you agree to these terms. Please cancel now if otherwise. 2. You must have the domain name(s) for which you want certificates pointing at the external IP address of this machine. 3. Both ports 80 and 443 on the external IP address of this machine must point to this machine (e.g. port forwarding might need to be setup on your router). Have you met these requirements? (y/n)

Type y to continue.

Next, you will be asked to provide an email address to use for recovery operations:

Output
Please enter an email address (for urgent notices or key recovery): your_email@domain.com

Finally, enter the domain name associated with your Nextcloud server:

Output
Please enter your domain name(s) (space-separated): example.com

Your Let’s Encrypt certificate will be requested and, provided everything went well, the internal Apache instance will be restarted to immediately implement SSL:

Output
Attempting to obtain certificates... done Restarting apache... done

You can now skip ahead to sign into Nextcloud for the first time.

Option 2: Setting Up SSL with a Self-Signed Certificate

If your Nextcloud server does not have a domain name, you can still secure the web interface by generating a self-signed SSL certificate. This certificate will allow access to the web interface over an encrypted connection, but will be unable to verify the identity of your server, so your browser will likely display a warning.

To generate a self-signed certificate and configure Nextcloud to use it, type:

  1. sudo nextcloud.enable-https self-signed
Output
Generating key and self-signed certificate... done Restarting apache... done

The above output indicates that Nextcloud generated and enabled a self-signed certificate.

Now that the interface is secure, open the web ports in the firewall to allow access to the web interface:

  1. sudo ufw allow 80,443/tcp

You are now ready to log into Nextcloud for the first time.

Logging in to the Nextcloud Web Interface

Now that Nextcloud is configured, visit your server’s domain name or IP address in your web browser:

https://example.com

Note: If you set up a self-signed SSL certificate, your browser may display a warning that the connection is insecure because the server’s certificate is not signed by a recognized certificate authority. This is expected for self-signed certificates, so feel free to click through the warning to proceed to the site.

Since you have already configure an administrator account from the command line, you will be taken to the Nextcloud login page. Enter the credentials you created for the administrative user:

Nextcloud login page

Click the Log in button to log in to the Nextcloud web interface.

The first time you enter, a window will be displayed with links to various Nextcloud clients that can be used to interact with and manage your Nextcloud instance:

Nextcloud client modal

Click through to download any clients you are interested in, or exit out of the window by clicking the X in the upper-right corner. You will be taken to the main Nextcloud interface, where you can begin to upload and manage files:

Nextcloud main page

Your installation is now complete and secured. Feel free to explore the interface to get more familiarity with the features and functionality of your new system.

Conclusion

Nextcloud can replicate the capabilities of popular third-party cloud storage services. Content can be shared between users or externally with public URLs. The advantage of Nextcloud is that the information is stored securely in a place that you control.

Explore the interface and for additional functionality, install plugins using Nextcloud’s app store.


Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up
About the authors
Default avatar
Developer and author at DigitalOcean.

Still looking for an answer?

Was this helpful?
10 Comments

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

This worked for me with one small hitch. I put an exclamation point in my password, like this:

sudo nextcloud.manual-install sammy pass!word

So that bash won’t interpret your password, consider putting single quotes around it:

sudo nextcloud.manual-install sammy ‘pass!word’

Details here: https://github.com/nextcloud/nextcloud-snap/issues/481

Hey, Everything seemed to work fine but when I go to the login page it will not accept the password I entered when I manually configured the admin account. Any help would be appreciated.

Did your intern write this article? Me stupid fool just followed this blindly and now my server is in a mess!

#!/bin/bash
ocpath='/var/www/nextcloud'
htuser='www-data'
htgroup='www-data'
rootuser='root'

printf "Creating possible missing Directories\n"
mkdir -p $ocpath/data
mkdir -p $ocpath/assets
mkdir -p $ocpath/updater

Guess what? This created those three direcotries directly in the root folder! And yes, you know what happens next, chmod operations in the root directory.

I guess I have to reinstall, my root user is not even allowed to run commands like chown, ls etc. anymore - Permission denied baby!

One abort condition in this script would have done the job (e.g. if ocpath is / then abort!).

Stupid, really, Especially as I am not the first victim (see posts below) and you are too lazy to change it.

Ok so after I ran the nextcloud.sh script I am now locked out of my server somehow and I get the following errors:

Creating possible missing Directories chmod Files and Directories xargs: chmod: Permission denied /tmp/nextcloud.sh: line 14: /usr/bin/find: Permission denied /tmp/nextcloud.sh: line 14: /usr/bin/xargs: Permission denied /tmp/nextcloud.sh: line 15: /bin/chmod: Permission denied chown Directories /tmp/nextcloud.sh: line 18: /bin/chown: Permission denied /tmp/nextcloud.sh: line 19: /bin/chown: Permission denied /tmp/nextcloud.sh: line 20: /bin/chown: Permission denied /tmp/nextcloud.sh: line 21: /bin/chown: Permission denied /tmp/nextcloud.sh: line 22: /bin/chown: Permission denied /tmp/nextcloud.sh: line 23: /bin/chown: Permission denied /tmp/nextcloud.sh: line 24: /bin/chown: Permission denied /tmp/nextcloud.sh: line 26: /bin/chmod: Permission denied chmod/chown .htaccess tpeterson@Einstein:/tmp$ su - -bash: /bin/su: Permission denied tpeterson@Einstein:/tmp$ su - -bash: /bin/su: Permission denied tpeterson@Einstein:/tmp$ cd tpeterson@Einstein:~$ su - -bash: /bin/su: Permission denied tpeterson@Einstein:~$ root root: command not found tpeterson@Einstein:~$ su - root -bash: /bin/su: Permission denied tpeterson@Einstein:~$ cd /tmp tpeterson@Einstein:/tmp$ ls -al -bash: /bin/ls: Permission denied tpeterson@Einstein:/tmp$ cd tpeterson@Einstein:~$ ls -bash: /bin/ls: Permission denied tpeterson@Einstein:~$ htop -bash: /usr/bin/htop: Permission denied tpeterson@Einstein:~$ su - -bash: /bin/su: Permission denied

So now I cannot do anything on my server. I can’t even ssh into it to try and troubleshoot it and this is on my Ubuntu 16.04.1 server I have at my home. PLEASE HELP!!

Hi guys,

When I try to set up the nextclowd user account:

sudo nextcloud.manual-install sammy password

(obviously with my own name and password)

I get the following error:

[Symfony\Component\Console\Exception\CommandNotFoundException] Command “maintenance:install” is not defined. Did you mean one of these? app:install maintenance:data-fingerprint maintenance:mimetype:update-db maintenance:mimetype:update-js maintenance:mode maintenance:repair maintenance:theme:update maintenance:update:htaccess

Any ideas on what to do?

Thanks for this nice tutorial! I have a major problem in the installation of the snap.

After I do:

sudo snap install nextcloud

I always get:

error: cannot perform the following tasks:
- Run configure hook of "nextcloud" snap if present (run hook "configure": cannot perform operation: mount --bind /snap/core/current//etc/nsswitch.conf /tmp/snap.rootfs_Vu0XTL/etc/nsswitch.conf: Permission denied)

I am trying to install Nextcloud on Xenial Mate Minimal Image from here: http://wiki.pine64.org/index.php/Pine_A64_Software_Release#Xenial_Mate

I don’t know how to proceed.

Thank you!

Hi, I installed nextcloud using snap as specified here https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-nextcloud-on-ubuntu-16-04 and now I’m stuck with the problem not it is possible to edit files (not enough rights). If I install Nextcloud myself without using snap, I get to edit the files. Tell me how you can fix the situation with the server that was installed with snap?

Good gracious, it took me forever to get over getting through let’s encrypt(just a full day actually)! In case you - a total newbie like I am - had your Nginx or whatever set up beforehand, you should stop nginx sending stuff through port 80 and 443, by sudo service nginx stop. Nextcloud snap has its own ways. Don’t hinder them with some other web server like nginx, like I did.

Hi all,

I recently decided to move from Google Apps to Nextcloud and found this tutorial on how to configure the software on DigitalOcean. It was a bit of a learning curve but managed to get it working to my liking. I must say, Nextcloud really exceeds my expectations and it feels great to know I’m now in control of my data.

Nonetheless, deploying and managing Nextcloud on your own server is definitely reserved to power users. This is especially true if you want to configure SSL and properly secure your server. So I decided to launch a service which will make it easy for anyone to do this. It’s called Cight and I’ll be launching shortly. Leave your email address on the website to be kept up to date.

I have developed the habit to thrust in Digital Ocean more than in software editors themselves, to produce clear instructions that work, to get the job done. Hence, I would like to know whether there is an intention to create a fork to this protocol for the installation of Nextcloud on Ubuntu 18.04. The current instruction worked seamlessly for Ubuntu 16.04 (with exception to LetsEncrypt that always failed), but doesn’t work as is for Ubuntu 18.04.

Nextcloud’s instructions are just not easy enough to be usable.