Installation and Setup Guide for NextCloud on Raspberry Pi with Ubuntu Server

Date: February 25, 2024
Author: Joseph El-Kadi

Introduction

NextCloud is a powerful, open-source file synchronization and sharing solution that allows individuals and organizations to host their own cloud storage platform.

This Document will provide step by step on how download, install, and setup your Raspberry Pi and NextCloud
These Steps are not limited to the exact Raspberry Pi (4) or Ubuntu Server 23.10 (64-bit) if there are later versions available to you, or if you have different machine you may use similiar steps as guidance. Feel free to do your own research to overpass any road blocks.

Prerequisites

Before proceeding with the installation, ensure you have the following:

Installation Steps

    Step 1: Prepare Ubuntu Server Image

  1. Download Raspberry Pi Imager: Visit Raspberry Pi Software and download the Raspberry Pi Imager.
  2. Prepare SD Card: Insert the SD Card into your PC and open the Raspberry Pi Imager.
    • Select your Raspberry Pi device
    • Choose "Other general-purpose OS"
    • Choose "Ubuntu"
    • Choose "Ubuntu Server 23.10 (64-Bit)" (or later version)
  3. Configure Settings:
    Windows: (CTRL + Shift ⇧ + ⨉)
    Mac: (⌘ + Shift ⇧ + ⨉)
    • Setup your hostname (this will be your machine's name)
    • Setup your username and password
    • Setup Locale Settings
    • Enable SSH under the SERVICES tab
  4. Install Ubuntu Server Image: Proceed to install the Ubuntu Server image on your SD Card.
  5. Step 2: Connect to Raspberry Pi

    If you're working directly on the Raspberry Pi, skip the next step.
    Otherwise, follow these steps to connect remotely:

  6. Open Terminal (Windows) or Terminal (Mac): Use the appropriate terminal application.
    Windows: Open Terminal, Command Prompt, or PowerShell
    Mac: Open Terminal
  7. SSH into Raspberry Pi: (replace 'username' and 'hostname' with your chosen credentials).
  8. $
    ssh username@hostname

    username would be the username you used in point 3
    hostname would be the hostname you used in point 3
    (If you run into issues with your hostname, you may use the IP address of your Raspberry Pi)
    "ssh: Could not resolve hostname fl1ght5network: No such host is known."
    (in my case it is FL1GHT5@FL1GHT5Network or FL1GHT5@10.1.1.5)

    Step 3: Install and Configure NextCloud

  9. Upgrade and Update Ubuntu Server:
  10. $
    sudo apt-get upgrade

    $
    sudo apt-get update

    $
    sudo apt update

    $
    sudo apt upgrade
  11. Install Snap Daemon:
  12. $
    sudo apt install snapd
  13. Verify Snap Version:
  14. $
    sudo snap version
    Output:
        snap    2.61.1
        snapd   2.61.1
        series  16
        ubuntu  23.10
        kernel  6.5.0-1005-raspi
                                
  15. Install NextCloud:
  16. $
    sudo snap install nextcloud
  17. Verify NextCloud Installation:
  18. $
    sudo snap list
    Output:
        Name       Version       Rev    Tracking       Publisher   Notes
        core18     20231027      2810   latest/stable  canonical✓  base
        core22     20230801      867    latest/stable  canonical✓  base
        lxd        5.20-f3dd836  27054  latest/stable  canonical✓  -
        nextcloud  27.1.6snap1   40247  latest/stable  nextcloud✓  -
        snapd      2.61.1        20674  latest/stable  canonical✓  snapd
                                
  19. Configure Firewall:
  20. $
    sudo ufw allow 80/tcp
    Output:
        Rules updated
        Rules updated (v6)
                                
    $
    sudo ufw allow 443/tcp
    Output:
        Rules updated
        Rules updated (v6)
                                
    $
    sudo ufw reload
  21. Access NextCloud Web Interface: Visit http://{Raspberry Pi - IP Address} in your web browser.
  22. (in my case it is http://10.1.1.5)
    Remember to keep it as HTTP and not HTTPS, We have not YET setup an SSL certificate with web encryption to use HTTPS.

  23. Enter a username and strong password to create the first administrator account, and click Install.
  24. Create Administrator Account: Enter a username and strong password to create the first administrator account.
  25. Edit Configuration File:
  26. $
    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.

    Output:
        Output:
        'trusted_domains' =>
            array (
                0 => 'nextcloud.example.com',
            ),
                                

    Edit the trusted_domains to be similiar to the following:

    Output:
        'trusted_domains' =>
        array (
            0 => 'localhost',
    
            1 => 'https://your_Domain_Name', 
            # (if you have a domain name such as FL1GHT5.net)
    
            2 => 'your_device_ip_address',   
            # (in my case it is 10.1.1.2)
    
            3 => 'your_public_ip_address'    
            # (you can use sites like https://whatismyipaddress.com/ to find your IPv4 Public IP Address)
        ),
                                
  27. Modify Trusted Domains: Update 'trusted_domains' with your domain name and IP address.
  28. Install Let's Encrypt SSL Certificate:
  29. $
    sudo nextcloud.enable-https lets-encrypt
    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) Y
        Please enter an email address (for urgent notices or key recovery): {your_email@address}
        Please enter your domain name(s) (space-separated): {your_domain.name}
                                
  30. Restart NextCloud:
  31. $
    sudo snap disable nextcloud

    $
    sudo snap enable nextcloud
  32. Access NextCloud Dashboard: Visit https://{your_domain_name} or https://{your_public_ip_address} in your web browser.
  33. Step 4: Mount External Drive (Optional)

    If you wish to mount an external drive for data storage, follow these additional steps:

  34. Plug in External Drive.
  35. List Drives:
  36. $
    lsblk -a
    Output:
        NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
        loop0         7:0    0  68.5M  1 loop /snap/core22/867
                                        /snap/core22/867
        loop1         7:1    0   169M  1 loop /snap/lxd/25953
                                        /snap/lxd/25953
        loop2         7:2    0  35.5M  1 loop /snap/snapd/20298
                                        /snap/snapd/20298
        loop3         7:3    0  35.2M  1 loop /snap/snapd/20674
                                        /snap/snapd/20674
        loop4         7:4    0 134.1M  1 loop /snap/lxd/27054
                                        /snap/lxd/27054
        loop5         7:5    0  49.1M  1 loop /snap/core18/2810
                                        /snap/core18/2810
        loop6         7:6    0 296.1M  1 loop /snap/nextcloud/40247
                                        /snap/nextcloud/40247
        loop7         7:7    0     0B  0 loop
        sda           8:0    0   3.6T  0 disk
        └─sda1        8:1    0   3.6T  0 part
        mmcblk0     179:0    0  28.9G  0 disk
        ├─mmcblk0p1 179:1    0   512M  0 part /boot/firmware
        └─mmcblk0p2 179:2    0  28.4G  0 part /snap
                                        /
    
        ({your_disk_name} is in my case the sda)
                                
  37. Partition and Format Drive:
  38. $
    sudo gdisk /dev/{your_disk_name}
    Output:
        GPT fdisk (gdisk) version 1.0.9
    
        Partition table scan:
            MBR: protective
            BSD: not present
            APM: not present
            GPT: present
    
        Found valid GPT with protective MBR; using GPT.
        Command (? for help): d
    
           Prtition number (1-2): 1
           Command (? for help): d
           Using 2
           Command (? for help): w
    
        Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
        PARTITIONS!!
      
        Do you want to proceed? (Y/N): y
        OK; writing new GUID partition table (GPT) to /dev/{your_disk_name}.
        The operation has completed successfully.
                                
  39. Create new GPT table:
  40. $
    sudo gdisk /dev/{your_disk_name}
    Output:
        GPT fdisk (gdisk) version 1.0.9
    
        Partition table scan:
            MBR: protective
            BSD: not present
            APM: not present
            GPT: present
    
        Found valid GPT with protective MBR; using GPT.
    
        Command (? for help): n
        Partition number (1-128, default 1): 1
        First sector (34-7813969886, default = 2048) or {+-}size{KMGTP}:
        Last sector (2048-7813969886, default = 7813967871) or {+-}size{KMGTP}:
        Current type is 8300 (Linux filesystem)
        Hex code or GUID (L to show codes, Enter = 8300):
        Changed type of partition to 'Linux filesystem'
    
        Command (? for help): w
    
        Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
        PARTITIONS!!
    
        Do you want to proceed? (Y/N): y
        OK; writing new GUID partition table (GPT) to /dev/{your_disk_name}.
        The operation has completed successfully.
                                
  41. Check your Disk:
  42. $
    sudo fdisk -l

    (You will notice that you have successfully created a GPT partition to your disk look for /dev/{your_disk_name}1 in my case this is /dev/sda1)

    Mount Drive Upon Boot:

  43. Get your Drive UUID
  44. $
    sudo blkid

    (copy the UUID of /dev/{your_disk_name}1 >> UUID"{your_disk_uuid}")

    $
    sudo vi /etc/fstab

    Press [INSERT] key to start typing

    Enter the following:
        # Cloud Storage
        UUID=8a48a5e7-1b95-4b77-80fd-d3cf88ea85e7 /snap ext4 defaults 0 0
                                

    Press [ESC] key then type :wq to write and quit followed by [ENTER] key

  45. Create the directory
  46. $
    cd /mnt

    $
    mkdir /mnt/cloud
  47. Reload Mount:
  48. $
    sudo mount -av
  49. Check Mount:
  50. $
    df -h
  51. Change NextCloud Data Directory to be your external drive
  52. $
    sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php

Resources I have complied and used to make this project possible:

NextCloud Documentation: Installation on Linux

VULTR Documentation: How to Install NextCloud on Ubuntu 22.04 with Snap

DigitalOcean: How To Install and Configure Nextcloud on Ubuntu 20.04

Tech Guides: How to Partition, Format, and auto Mount Disk on Ubuntu 20.04

Tech Guides: How to Install Nextcloud on Ubuntu, Move Data Directory, Setup Free DDNS Domain & SSL Certificate