1. Overview

Nextcloud is an open-source software suite that enables users to create their own cloud storage solution. Unlike traditional cloud storage providers, Nextcloud can run on-premises. This provides full control of their data, ensuring the highest level of privacy and security.

On the other hand, Snap refers to a software packaging and deployment system that offers a unique approach to installing and managing applications on Linux. In particular, it’s beneficial for its simplicity and wide compatibility.

In this tutorial, we’ll go through a step-by-step guide to install and configure the Nextcloud Snap on Linux.

Notably, we’ll perform this operation on Ubuntu. However, the same process can apply to other distributions as well.

2. Installing the Nextcloud Snap

Firstly, let’s check if the system has an installation of the Snap package manager:

$ snap version
snap 2.61.3
snapd 2.61.3
series 16
ubuntu 23.04
kernel 6.5.0-26-generic

Visibly, the Snap version that the machine contains is 2.61.3.

If we encounter an error, then Snap probably doesn’t exist on the system.

In this case, we go ahead and install that first using the native distribution package manager:

$ sudo apt install snapd

Next, let’s install the Nextcloud Snap package on the machine:

$ sudo snap install nextcloud

The installation might take a few minutes depending on the network speed.

3. Setting up an Administrative Account

Once the installation is complete, we have to set up an administrative account for accessing Nextcloud:

$ sudo nextcloud.manual-install baeldung nextcloud

Above, the nextcloud.manual-install command creates an administrative account with baeldung as its username and nextcloud as its password.

Since we’ve finished setting up the account, let’s move on to the next step, which focuses on the modification of trusted domains.

4. Modifying the Trusted Domains

By default, localhost is the only domain that Nextcloud trusts and responds to. If we want to access Nextcloud via localhost, then no further action is required. However, if we plan to access the deployment via another domain, then we modify the trusted domains to include that particular domain.

To modify the trusted domains, we use a single command:

$ sudo nextcloud.occ config:system:set trusted_domains 1 --value= example.com

Since trusted_domains is an array and localhost is the only entry in the array, this indicates that localhost has an index of 0. Hence, we modify the –value field of the next index, i.e., 1, in the trusted_domains array and set it to example.com, the domain that we want to use.

After hitting Return, we can check trusted_domains to verify if it has the new domain in it:

$ sudo nextcloud.occ config:system:get trusted_domains
localhost
example.com

Evidently, Nextcloud now recognizes example.com as a trusted domain.

5. Securing Nextcloud With SSL

Before we start using Nextcloud, it’s recommended to secure it using SSL. To do that, we can follow several steps and obtain a trusted SSL certificate for our domain from Let’s Encrypt.

Firstly, let’s configure UFW (Uncomplicated Firewall) to enable HTTP network traffic on the server ports 80 and 443:

$ sudo ufw allow 80,443/tcp

Secondly, let’s secure Nextcloud with HTTPS by requesting a Let’s Encrypt SSL certificate:

$ sudo nextcloud.enable-https lets-encrypt

Once we hit Return, a prompt appears about the target domain meeting the requirements necessary to obtain a Let’s Encrypt SSL certificate:

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) yes

Above, we type yes in the terminal and proceed to the next step.

After that, we have to input an email address to be used for urgent notices or key recovery. Here, we type an email address and hit Return to proceed:

Please enter an email address (for urgent notices or key recovery):

Finally, let’s enter the domain name that we want to secure using an SSL certificate:

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

After hitting Return, an SSL certificate is requested and obtained for example.com and we see the respective output in the terminal:

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

So, we’ve completed installing and configuring Nextcloud on the machine. Now, we just navigate to https://example.com in a Web browser and input the username and password of the administrative account to access our personal cloud storage solution.

6. Conclusion

In this article, we had a detailed discussion about installing and configuring the Nextcloud Snap on Linux. The process may look a bit tricky, but it’s fairly straightforward if we follow the steps carefully.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.