How to Install NextCloud on Ubuntu 22.04 with Snap
Introduction
NextCloud is an open-source, self-hosted file management platform that allows you to create, edit, host, and share files without restrictions. This guide covers how to install NextCloud on Ubuntu 22.04 server using Snap and how to secure it for production use.
Snaps are Linux packages that are easy, quick, and dependency-free to install on a server. The NextCloud Snap package consists of the following components:
- PHP
- MySQL
- Redis®
- Apache2.4
- mDNS
- NextCloud 24
Prerequisites
- Deploy a fresh Ubuntu server on Vultr.
- Set up a subdomain A record pointing to the server.
- Use SSH to access the server console as a non-root user with sudo privileges.
- Update the Server.
Installation
By default, the Snap daemon is active on most Ubuntu server distributions. In any case, install it using the following command.
$ sudo apt install snapd
Verify the installed snap version.
$ sudo snap version
Output:
snap 2.57.1 snapd 2.57.1 series 16 ubuntu 22.04 kernel 5.15.0-41-generic
Install NextCloud.
$ sudo snap install nextcloud
Verify that NextCloud is successfully installed
$ sudo snap list
Configure NextCloud
NextCloud files are all stored in the /snap/nextcloud/current/htdocs/
directory, and the configuration file in the /var/snap/nextcloud/current
directory. To enable NextCloud access on your domain name, include it in the trusted domains array of the configuration file.
First, configure Uncomplicated Firewall (UFW) to allow HTTP network traffic on the server port
80
.$ sudo ufw allow 80/tcp
Allow HTTPS on port
443
.$ sudo ufw allow 443/tcp
Restart the Firewall.
$ sudo ufw reload
To activate the NextCloud database and configuration file values, visit your Server IP using a web browser.
http://192.0.2.1
Enter a username and strong password to create the first administrator account, and click Install.
Close the web browser and switch to your server console.
Using a text editor of your choice, edit the main NextCloud configuration file.
$ sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php
Find the "trusted_domains' =>` section, and replace the Server IP with your domain name as below.
'trusted_domains' => array ( 0 => 'nextcloud.example.com', ),
Save and close the file.
Install a Let's Encrypt SSL certificate to secure your NextCloud server with HTTPS by running the following command.
$ sudo nextcloud.enable-https lets-encrypt
Your output should look like the one below.
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)
Enter `y' to accept all SSL certificate requirements, enter your email address, then enter your domain name.
Restart NextCloud to load changes.
Using a web browser of your choice, visit your server domain name.
https://nextcloud.example.com
Login using the administrator username and password you created earlier to access the NextCloud dashboard.
Next Steps
You have installed NextCloud on Ubuntu 22.04 server using Snap. Please refer to the following articles to power up your NextCloud server with more features.