step-by-step guide to self-hosting Nextcloud on a Raspberry Pi

Step-by-Step Guide to Self-Hosting Nextcloud on a Raspberry Pi What You Need: Equipment and Preparation To self-host Nextcloud on a Raspberry Pi, you will need the following: Hardware: Raspberry Pi (3, 4, or later recommended)

Written by: David Choi

Published on: October 21, 2025

Step-by-Step Guide to Self-Hosting Nextcloud on a Raspberry Pi

What You Need: Equipment and Preparation

To self-host Nextcloud on a Raspberry Pi, you will need the following:

  1. Hardware:

    • Raspberry Pi (3, 4, or later recommended)
    • Micro SD Card (16GB or larger)
    • Power Supply (official Raspberry Pi PSU recommended)
    • External USB Drive (for file storage; optional but recommended)
    • Internet Connection
  2. Software:

    • Raspbian OS (Raspberry Pi OS)
    • Nextcloud Software
    • Web server (Apache or Nginx)
    • PHP and required extensions
    • Database (MariaDB or SQLite)
  3. Preparation:

    • Update your Raspberry Pi OS. Connect to your Raspberry Pi via SSH or directly and run:
      sudo apt update && sudo apt upgrade -y

Step 1: Install Required Packages

You will need to install several packages to run Nextcloud. Use the following command:

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

Make sure you are installing the most compatible PHP version with Nextcloud. Check the official Nextcloud documentation for the latest version info.

Step 2: Configure the Database

  1. Start the MariaDB server:
sudo systemctl start mariadb
  1. Secure your MariaDB installation:
sudo mysql_secure_installation
  • Follow the prompts to set a root password and secure your database.
  1. Log into MariaDB:
sudo mysql -u root -p
  1. Create a database and a user for Nextcloud:
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'your_password_here';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 3: Install Nextcloud

  1. Navigate to the directory for your web files:
cd /var/www/html
  1. Download the latest version of Nextcloud:
wget https://download.nextcloud.com/server/releases/nextcloud-XX.0.0.zip

(Replace XX.0.0 with the latest version number.)

  1. Unzip the downloaded file:
sudo apt install unzip
sudo unzip nextcloud-XX.0.0.zip
  1. Set the appropriate permissions:
sudo chown -R www-data:www-data nextcloud
sudo chmod -R 755 nextcloud

Step 4: Configure Apache

  1. Create a new Apache configuration file for Nextcloud:
sudo nano /etc/apache2/sites-available/nextcloud.conf
  1. Add the following configuration:
<VirtualHost *:80>
    DocumentRoot /var/www/html/nextcloud
    ServerName your_domain_or_IP

    <Directory /var/www/html/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
    CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>
  1. Enable the necessary Apache modules:
sudo a2enmod rewrite
sudo a2ensite nextcloud.conf
  1. Restart Apache:
sudo systemctl restart apache2

Step 5: Finalizing Nextcloud Installation

  1. Navigate to your Nextcloud instance via a web browser:
http://your_domain_or_IP
  1. Create the Nextcloud admin account by entering the desired username and password.

  2. Configure the database settings:

    • Database user: nextclouduser
    • Database name: nextcloud
    • Database password: your_password_here
  3. Click on “Finish setup” to complete the installation.

Step 6: Configure Data Directory (Optional)

For better performance and storage management, it’s advisable to move your Nextcloud data directory to an external USB drive.

  1. Format the USB drive to ext4:
sudo mkfs.ext4 /dev/sda1
  1. Create a mount point:
sudo mkdir /media/nextcloud
  1. Edit the fstab file to mount the drive at boot:
sudo nano /etc/fstab
  1. Add the entry:
/dev/sda1 /media/nextcloud ext4 defaults 0 0
  1. Mount the USB drive:
sudo mount -a
  1. Set the data directory in Nextcloud:
sudo -u www-data php /var/www/html/nextcloud/occ config:system:set --value="/media/nextcloud" datadirectory

Step 7: Enhance Security

  1. Enable HTTPS using Let’s Encrypt:
sudo apt install certbot python3-certbot-apache
  1. Run the Certbot tool to obtain your SSL certificate:
sudo certbot --apache

Follow the prompts to set up HTTPS for your domain.

Step 8: Access and Test Nextcloud

  1. Access your Nextcloud URL via HTTPS:
https://your_domain_or_IP
  1. Log in with your admin credentials and explore the features.

Important Maintenance

  • Regular updates: Keep your Raspbian and Nextcloud installations updated to ensure security.
  • Backup: Regular backups of your data and database help secure against data loss.
  • Monitor system performance: Regularly check CPU usage and free space, especially if heavily used.

By closely following these steps, you can successfully self-host Nextcloud on a Raspberry Pi. This guide ensures that your data remains private and under your control, offering a robust alternative to traditional cloud storage solutions.

Leave a Comment

Previous

best open source infrastructure as code tools comparison

Next

best open source video editing software for youtube beginners