how to build your own Nextcloud server with Raspberry Pi

Prerequisites Before starting the process of building your own Nextcloud server using a Raspberry Pi, ensure you have the following materials: Raspberry Pi: A Raspberry Pi 3 Model B or later is recommended due to

Written by: David Choi

Published on: October 21, 2025

Prerequisites

Before starting the process of building your own Nextcloud server using a Raspberry Pi, ensure you have the following materials:

  1. Raspberry Pi: A Raspberry Pi 3 Model B or later is recommended due to enhanced performance.
  2. MicroSD Card: At least 16 GB or larger, preferably Class 10 for speed.
  3. Power Supply: A reliable power supply (at least 2.5A).
  4. External Storage: A USB drive or external HDD for file storage.
  5. Network Connection: Ethernet is recommended for stable connectivity over Wi-Fi.
  6. A Computer: For initial setup and configuration.

Step 1: Prepare Your Raspberry Pi

  1. Download Raspberry Pi OS: Head over to the official Raspberry Pi website and download the Raspberry Pi Imager software. Use it to install Raspberry Pi OS Lite (the headless version) onto your microSD card.

  2. Insert MicroSD Card into Raspberry Pi: Once the OS is written onto the microSD card, insert it into the Raspberry Pi.

  3. Boot Up the Raspberry Pi: Connect the power supply to boot the Raspberry Pi. Allow it a few moments to initialize.

  4. Connect via SSH: If you are using a headless setup, enable SSH by creating a file named ssh (no extension) in the boot partition of the microSD card. Use software such as PuTTY to connect to your Raspberry Pi via its assigned IP address.

  5. Change Default Password: Log in with the username pi and the default password raspberry. Change it immediately with the command passwd.

Step 2: Update Your Raspberry Pi

Before installing any software, update your Raspberry Pi:

sudo apt update
sudo apt upgrade -y

This command ensures that all your software packages are up to date, which is crucial for security and performance.

Step 3: Install Required Packages

Next, install the necessary software dependencies:

sudo apt install apache2 mariadb-server libapache2-mod-php7.3 
php7.3 php7.3-mbstring php7.3-xml php7.3-curl php7.3-zip 
php7.3-intl php7.3-gd php7.3-json php7.3-mysql -y

This command installs the web server (Apache), the database server (MariaDB), and the required PHP modules for Nextcloud.

Step 4: Configure MySQL Database

  1. Log into MySQL:
sudo mysql -u root -p
  1. Create a Database and User for Nextcloud:
CREATE DATABASE nextcloud;
CREATE USER 'nc_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nc_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace 'your_password' with a strong password of your choice.

Step 5: Download and Install Nextcloud

  1. Download Nextcloud:
cd /var/www/
sudo wget https://download.nextcloud.com/server/releases/nextcloud-XX.X.X.zip

Make sure to replace XX.X.X with the latest version number.

  1. Unzip the Downloaded File:
sudo apt install unzip
sudo unzip nextcloud-XX.X.X.zip
  1. Set Permissions:
sudo chown -R www-data:www-data /var/www/nextcloud/
sudo chmod -R 755 /var/www/nextcloud/

Step 6: Configure Apache for Nextcloud

  1. Create a New Apache Configuration File:
sudo nano /etc/apache2/sites-available/nextcloud.conf
  1. Add the Following Configuration:
<VirtualHost *:80>
    DocumentRoot /var/www/nextcloud
    ServerName your_domain_or_IP

    <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/nextcloud-error.log
    CustomLog ${APACHE_LOG_DIR}/nextcloud-access.log combined
</VirtualHost>

Replace your_domain_or_IP with your Raspberry Pi’s IP address or domain name.

  1. Enable the Configuration and Required Modules:
sudo a2ensite nextcloud.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

Step 7: Complete Nextcloud Installation via Web Interface

  1. Access Your Nextcloud Installation: Open a web browser and navigate to http://your_ip_address or http://your_domain_name.

  2. Follow the Installation Wizard: Create an admin account and input the database details you set up earlier. In the database name field, enter nextcloud, user nc_user, and provide the password.

  3. Storage Location: You can specify custom storage locations if your external drive is mounted.

  4. Finish Installation: Once the configuration is complete, you can log in and start using Nextcloud.

Step 8: Set Up External Storage (Optional)

If using external storage:

  1. Connect USB Drive: Plug in your USB drive.

  2. Identify Drive:

lsblk

Take note of the drive name, e.g., /dev/sda1.

  1. Mount the Drive: Create a mount point and mount the drive.
sudo mkdir /media/usb
sudo mount /dev/sda1 /media/usb
  1. Automatic Mounting: Add this line to /etc/fstab for automatic mounting:
/dev/sda1 /media/usb vfat defaults 0 0

Step 9: Secure Your Nextcloud Server

  1. Install SSL with Let’s Encrypt: For encrypted connections, you’ll want to secure your server using HTTPS.
sudo apt install certbot python3-certbot-apache
sudo certbot --apache

Follow the prompts to secure your connection.

  1. Regular Backups: Schedule regular backups of your Nextcloud data and database:
# Backup Command Example
sudo tar -cvf nextcloud-backup.tar.gz /var/www/nextcloud
sudo mysqldump -u root -p nextcloud > nextcloud-db-backup.sql

Step 10: Access and Use Your Nextcloud Server

Once configured, you can log into your Nextcloud server from any browser. Start uploading files, sharing them with users, and utilizing Nextcloud’s features such as file versioning, collaborative document editing, and calendar integration.

Final Note

Utilizing Raspberry Pi for hosting your Nextcloud server not only provides a private cloud solution but also gives you complete control over your data. Enjoy exploring the many features Nextcloud offers while developing your mini server expertise!

Leave a Comment

Previous

effective open source video editors for new youtube content creators

Next

open source diagramming tool that replaces lucidchart online