Installing Nextcloud on Raspberry Pi Part 02

Securing and Updating Your Raspberry Pi + Installing Nextcloud with Snap

Now that you’re logged into your Raspberry Pi via SSH, it’s time to prepare the system for a reliable and secure Nextcloud installation. We’ll start by updating the operating system, installing Snap, and then deploying Nextcloud using the official Snap package one of the simplest and most maintenance-friendly methods available.

The Snap version of Nextcloud bundles everything (web server, database, PHP, etc.) into a self-contained package. It handles automatic updates gracefully and is well-suited for Raspberry Pi hardware.

Step 1: Update and Upgrade the System

Run the following commands one by one:

Run Command
sudo apt update

Before installing any new software, always bring your Raspberry Pi OS up to date. This ensures you have the latest security patches and package versions.

Step 2: Install Snapd

Raspberry Pi OS (Debian Bookworm-based) does not include Snap support by default. Install it with these commands:

Run Command
sudo apt install snapd -y

To ensure you’re running the latest version of snapd itself, install the snapd snap:

Run Command
sudo snap install snapd

Important: Reboot the Pi again after installing snapd:

Run Command
sudo reboot

Log back in via SSH.

Step 3: Install Nextcloud via Snap

Now install the official Nextcloud Snap. This process may take several minutes as it downloads and sets up all components.

Run Command
sudo snap install nextcloud

Once the installation finishes, Nextcloud will start automatically. You can check its status with:

Run Command
sudo snap services nextcloud

Step 4: Initial Nextcloud Setup

Nextcloud runs on port 80 by default. Open a web browser on any device connected to the same network and navigate to your Raspberry Pi’s IP address:

http://IP-ADDRESS

(Replace IP-ADDRESS with the actual IP you found in your router.)

You will see the Nextcloud setup wizard. Create your admin account by entering:

Click Install to complete the initial setup. The process usually takes 1–2 minutes.

Basic Nextcloud Management Commands

Here are some useful commands you may need later:

Run Command
sudo snap restart nextcloud
Run Command
sudo snap logs nextcloud
Run Command
sudo snap refresh nextcloud

Storage Strategy: Using an External HDD with Dedicated Backup

For optimal data protection and reliability, we recommend using an external HDD as the primary storage for your Nextcloud files, combined with a separate drive dedicated exclusively to backups.

Why this approach?

Imagine losing your primary HDD or even the entire Raspberry Pi along with years of irreplaceable family photos, documents, and memories. With this setup, you’ll still have a complete, up-to-date copy of everything on your backup drive, ensuring your precious data remains safe even in the event of hardware failure.

This dual-drive strategy significantly reduces the risk of data loss and provides peace of mind, which is especially important when self-hosting personal and family data.

Raspberry Pi Nextcloud + External HDD Setup Guide

So now, we will configure two external hard drives on a Raspberry Pi: one for primary Nextcloud storage and a second for automated daily backups. This setup protects your data against drive failure or hardware issues while keeping everything accessible and easy to manage.

This guide provides the exact commands used to configure a Raspberry Pi running Raspberry Pi OS with Nextcloud (Snap installation).

Architecture Overview

1. Identify Attached Disks

Run Command
lsblk
Purpose

2. Create Mount Points

Run Command
sudo mkdir -p /mnt/drive1 
sudo mkdir -p /mnt/backup

Purpose

3. Format a New Disk (NTFS)

Run Command
sudo fdisk /dev/sdb
Purpose

4. Format the Partition

Run Command
sudo mkfs.ntfs -f /dev/sdb1
Purpose

5. Manual Mount Test

Run Command
sudo mount /dev/sdb1 /mnt/backup
df -h
Purpose

6. Permanent Mounting via fstab

Edit the fstab file:

Run Command
sudo nano /etc/fstab

Add the following entries (replace UUIDs with your actual values from blkid):

Run Command
UUID=XXXXXXXXXXXXXX /mnt/drive1 ntfs-3g defaults,uid=root,gid=root,umask=007,noatime 0 0
Run Command
UUID=YYYYYYYYYYYYYY /mnt/backup ntfs-3g defaults,uid=root,gid=root,umask=007,noatime 0 0

Test the configuration:

Run Command
sudo mount -a
Purpose

7. Repair NTFS Filesystem (if needed)

Run Command
sudo ntfsfix /dev/sda1
Purpose

8. Configure Nextcloud Data Directory (Snap)

The config file is located at:

Run Command
sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php

Change the datadirectory line to:

Run Command
'datadirectory' => '/mnt/drive1/nextcloud_data',
Important

For Snap installations, also run

Run Command
sudo snap connect nextcloud:removable-media

9. Prepare the Nextcloud Data Folder

Run Command
sudo mkdir -p /mnt/drive1/nextcloud_data
Run Command
echo "# Nextcloud data directory" | sudo tee /mnt/drive1/nextcloud_data/.ncdata
Purpose

10. Create Backup Directory

Run Command
sudo mkdir -p /mnt/backup/nextcloud_backup

11. Perform Initial Backup

Run Command
sudo rsync -avh --delete /mnt/drive1/nextcloud_data/ /mnt/backup/nextcloud_backup/
Purpose

12. Automate Daily Backups

Run Command
crontab -e

Add the following line:

Run Command
0 3 * * * rsync -a --delete /mnt/drive1/nextcloud_data/ /mnt/backup/nextcloud_backup/
Purpose

13. Check Disk Usage

Run Command
df -h /mnt/drive1 /mnt/backup
Purpose

Final Architecture

  • Raspberry Pi
    • SD Card (OS)
    • Drive 1 (/mnt/drive1)
      • nextcloud_data (Primary storage)
    • Drive 2 (/mnt/backup)
      • nextcloud_backup (Daily mirror)

Benefits of This Setup

The next guide explains the commands used to recover a Raspberry Pi from
emergency mode and manually mount external USB drives used for Nextcloud.

Follow Us
Our Locations