How to Install NextCloud on Ubuntu 22.04 with Snap

Updated on July 25, 2024
How to Install NextCloud on Ubuntu 22.04 with Snap header image

Introduction

NextCloud is an open-source, self-hosted file management application that lets you create, edit, host, and share files without limitations. This article explains how you can install NextCloud on a Ubuntu 22.04 server with Snap and secure the application 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

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
  1. 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
  2. Install NextCloud.

      $ sudo snap install nextcloud
  3. 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.

  1. First, configure Uncomplicated Firewall (UFW) to allow HTTP network traffic on the server port 80.

      $ sudo ufw allow 80/tcp
  2. Allow HTTPS on port 443.

      $ sudo ufw allow 443/tcp
  3. Restart the Firewall.

      $ sudo ufw reload
  4. To activate the NextCloud database and configuration file values, visit your Server IP using a web browser.

      http://192.0.2.1
  5. Enter a username and strong password to create the first administrator account, and click Install.

    NextCloud Snap installation page

    Close the web browser and switch to your server console.

  6. Using a text editor of your choice, edit the main NextCloud configuration file.

      $ sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php
  7. 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.

  8. 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)
  9. Enter `y' to accept all SSL certificate requirements, enter your email address, then enter your domain name.

  10. Restart NextCloud to load changes.

  11. Using a web browser of your choice, visit your server domain name.

     https://nextcloud.example.com
  12. Login using the administrator username and password you created earlier to access the NextCloud dashboard.

Next Steps

You have installed NextCloud on a Ubuntu 22.04 server using Snap. Please refer to the following articles to power up your NextCloud server with more features.