Nextcloud Install Guide (Raspberry Pi)

Step 1: Connect to Your Raspberry Pi

If you’re using a monitor and keyboard directly connected to the Raspberry Pi, log in using:

If you're using another computer or phone, the easiest way is to use an SSH app.

🔷 Recommended: Termius

🖥️ Alternative for Windows: PuTTY

If the above address doesn’t work, skip to Step 7 to find your Raspberry Pi’s IP address.

Step 2: Update Your Raspberry Pi

This makes sure all the software is up to date.

sudo apt update && sudo apt upgrade -y

Step 3: Install Web Server and PHP

This installs Apache, MariaDB, and PHP so Nextcloud can run.

sudo apt install apache2 mariadb-server libapache2-mod-php php php-mysql php-gd php-json php-curl php-mbstring php-intl php-imagick php-xml php-zip php-bcmath php-gmp unzip -y

Step 4: Set Up the Database

Nextcloud needs a database to store usernames, settings, and file info. We'll use MariaDB, a lightweight version of MySQL.

🔹 A. Open the MariaDB Console

This command lets you interact with the database server:

sudo mariadb

🔸 If prompted for a password, just press Enter (there is no password set by default).

🔹 B. Create the Database and User

Copy and paste the following commands one by one into the MariaDB prompt:

CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Here’s what each line does:

🛡️ Tip:

Make sure to remember the username and password — you'll need them when setting up Nextcloud in your browser later.

Step 5: Configure Apache

In this step, you'll tell Apache where to find your Nextcloud files and how to serve them to browsers.

🔹 A. Create a New Apache Configuration File

This file will define how your site is accessed:

sudo nano /etc/apache2/sites-available/nextcloud.conf

Paste the following into the file:

<VirtualHost *:80>
  DocumentRoot /var/www/html/nextcloud
  ServerName your-pi-ip

  <Directory /var/www/html/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  </Directory>
</VirtualHost>

🔸 Replace your-pi-ip with your Raspberry Pi’s IP address or your No-IP domain name (e.g., mypihost.ddns.net).

🔹 B. Enable the New Site and Required Modules

These commands activate your config and enable necessary Apache features:

sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime

What each command does:

🔹 C. Restart Apache

This applies the changes:

sudo systemctl restart apache2

💡 Tips for Beginners:

Step 6: Find Pi's IP Address

hostname -I

Use the IP to access your Pi in a browser.

Step 7: Finish in Browser

Open a browser and go to:

http://192.168.x.x/nextcloud

Replace IP with yours. Use:

Step 8: Enable Services

sudo systemctl enable apache2
sudo systemctl enable mariadb

Step 9: Mount External HDD (Optional)

If you want to use an external hard drive for storing Nextcloud files, follow these steps to mount it permanently.

🔹 A. Plug in Your Drive

Connect your USB hard drive to the Raspberry Pi.

🔹 B. Find the Drive Name

Run this command to list all storage devices:

lsblk

Look for something like /dev/sda1 with a size that matches your drive. Make note of the name (e.g., sda1).

🔹 C. Create a Mount Point

This is the folder where the drive will be accessed from:

sudo mkdir /media/nextcloud-hdd

🔹 D. Mount the Drive Manually (Temporary)

sudo mount /dev/sda1 /media/nextcloud-hdd

This temporarily mounts the drive. But it won’t survive a reboot—so next we’ll set up auto-mounting.

🔹 E. Get the Drive’s UUID

The UUID is a unique ID that doesn’t change, even if the drive’s name changes:

sudo blkid

Find the line for /dev/sda1 (or your device) and copy the UUID value.

🔹 F. Edit the fstab File (Permanent Mount)

This file controls what gets mounted at boot:

sudo nano /etc/fstab

At the bottom, add a new line using the UUID you copied:

UUID=xxxx-xxxx /media/nextcloud-hdd ext4 defaults,nofail 0 2

⚠️ Replace xxxx-xxxx with your actual UUID. If your drive is NTFS or exFAT, change ext4 to ntfs or exfat.

🔹 G. Test It

Make sure your changes work:

sudo mount -a

If there are no errors, your drive is now permanently mounted!

🔍 Tip:

You can check if it worked by running:

df -h

This shows mounted drives and their available space.

Step 10: Give Access to External Hard Drive (Optional)

To allow Nextcloud to read and write files to your mounted HDD, you need to give proper permissions to the web server (Apache).

🔹 A. Change Ownership to Apache

This gives full control of the drive to Apache's default user www-data:

sudo chown -R www-data:www-data /media/nextcloud-hdd

What it does: This command recursively (-R) changes the owner of all files and folders inside the HDD mount point to the web server user.

🔹 B. Adjust File Permissions

This ensures that the Apache server can read, write, and execute within the mounted folder:

sudo chmod -R 750 /media/nextcloud-hdd

What it means:

This keeps the drive secure while letting Nextcloud function properly.

🔹 C. Add Nextcloud Data Directory (Optional)

If you want Nextcloud to store user files directly on the HDD, create a dedicated folder:

sudo mkdir /media/nextcloud-hdd/data
sudo chown -R www-data:www-data /media/nextcloud-hdd/data

Then, during the browser setup in Step 7, set the Data Folder as:

/media/nextcloud-hdd/data

✅ Done!

Your HDD is now ready for Nextcloud file storage with proper permissions and access control.

Step 11: Enable HTTPS (Optional but Recommended)

HTTPS encrypts your connection, making it safer—especially if you plan to access your Nextcloud over the internet.

🔹 A. Install Certbot (Let's Encrypt)

This tool automatically sets up a free SSL certificate from Let's Encrypt.

sudo apt install certbot python3-certbot-apache -y

🔹 B. Run Certbot

This command will configure your Apache web server to use HTTPS:

sudo certbot --apache

When you run it:

If successful, you’ll see a confirmation and your site will now be accessible at:

https://yourname.ddns.net/nextcloud

🔄 C. Auto-Renewal (Built-In)

Certbot sets up automatic renewal by default. You can test it with:

sudo certbot renew --dry-run

⚠️ Note:

If your router or firewall blocks port 80 or 443, this will fail. Make sure those ports are forwarded to your Raspberry Pi’s IP address.

Step 12: Download Nextcloud and Set Up No-IP Access

🔹 A. Download Nextcloud

This installs the Nextcloud files into your web directory.

cd /var/www/html
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo chown -R www-data:www-data nextcloud
sudo chmod -R 755 nextcloud

🔹 B. Set Up No-IP Dynamic DNS (Optional)

This lets you access your Raspberry Pi remotely using a hostname like yourname.ddns.net.

1. Create Your No-IP Account

2. Install the No-IP Client on Pi

cd ~
sudo apt install git build-essential -y
git clone https://github.com/no-ip/noip-ddns
cd noip-ddns
make
sudo make install

During setup, enter your No-IP email, password, and hostname.

3. Start and Enable No-IP Client

sudo /usr/local/bin/noip2
sudo /usr/local/bin/noip2 -S

4. Make No-IP Run on Boot

sudo nano /etc/systemd/system/noip2.service

Paste this:

[Unit]
Description=No-IP Dynamic DNS Update Service
After=network.target

[Service]
ExecStart=/usr/local/bin/noip2
Restart=always

[Install]
WantedBy=multi-user.target
sudo systemctl enable noip2
sudo systemctl start noip2

✅ Access Nextcloud Remotely

Now go to:

http://yourname.ddns.net/nextcloud

This will redirect to your Raspberry Pi, even if your home IP changes.