Nextcloud is an open-source file hosting software that allows you to set up your own cloud storage server. With Nextcloud and a Raspberry Pi, you can have complete control over your data and build a low-cost, energy-efficient private cloud.

In this step-by-step beginner‘s guide, I will walk you through installing Nextcloud on a Raspberry Pi.

Prerequisites

Before we get started, here is what you‘ll need:

  • A Raspberry Pi (I used a Raspberry Pi 4 Model B)
  • A microSD card (16GB or larger recommended)
  • Raspberry Pi OS installed on the SD card
  • A power supply for the Pi
  • Network connectivity (Ethernet or WiFi enabled)

Step 1 – Set Up Raspberry Pi

The first step is to get Raspberry Pi up and running.

  1. Insert the microSD card with Raspberry Pi OS into your Pi.

  2. Connect the Pi to your monitor using an HDMI cable.

  3. Plug in your keyboard, mouse, Ethernet cable/WiFi dongle, and finally the power supply.

The Pi should boot up to the Raspberry Pi OS desktop environment. Next, we‘ll make sure the OS is up to date.

  1. Open a terminal window and run:
sudo apt update
sudo apt full-upgrade

This installs the latest security patches and updates for the OS packages. Reboot once done.

With the Pi updated, it‘s now ready for installing Nextcloud.

Step 2 – Install Apache, PHP and Database

Nextcloud requires a web server, PHP and a database to run. We‘ll install these next.

  1. Install the Apache web server by typing:
sudo apt install apache2 -y
  1. Enable a few common Apache modules needed:
sudo a2enmod rewrite headers env dir mime
  1. Install PHP and some extra modules:
sudo apt install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-apcu php-smbclient php-ldap php-redis php-gd php-xml php-intl php-json php-imagick php-mysql php-cli php-mcrypt php-ldap php-zip php-curl
  1. Next install MariaDB, a MySQL compatible database:
sudo apt install mariadb-server -y

Say yes when asked. Also run sudo mysql_secure_installation and answer the questions to secure MariaDB.

With the base components installed, we can now add a dedicated user for Nextcloud.

Step 3 – Create Nextcloud User

It‘s best practice to not run applications as root. So we‘ll make a new user called "nextcloud" for running the Nextcloud server.

  1. Add new user with:
sudo adduser nextcloud

Set a password when prompted.

  1. Add user to the www-data group to give web server access:
sudo usermod -a -G www-data nextcloud

Now let‘s create the database next.

Step 4 – Create Database

Here we create a MariaDB database for Nextcloud to utilize:

  1. Login to MariaDB console as root:
sudo mysql -u root -p

Enter password when asked.

  1. Create new database:
CREATE DATABASE nextclouddb; 
  1. Create a user for this database:
GRANT ALL ON nextclouddb.* TO ‘nextcloud‘@‘localhost‘ IDENTIFIED BY ‘password123‘;

Replace "password123" with your desired database password.

  1. Flush privileges and exit:
FLUSH PRIVILEGES;
exit

The MariaDB database is now ready for Nextcloud.

Step 5 – Install Nextcloud

With all the prerequisites ready, let‘s install Nextcloud.

  1. Switch to the nextcloud user:
sudo su - nextcloud
  1. Navigate to web root directory:
cd /var/www
  1. Download latest Nextcloud tarball (check nextcloud.com for latest version):
wget https://download.nextcloud.com/server/releases/nextcloud-24.0.2.zip
  1. Unzip Nextcloud:
unzip nextcloud-*.zip
  1. Set correct permissions:
sudo chown -R www-data:www-data /var/www/nextcloud/

Now we can enable Nextcloud on Apache.

Step 6 – Enable Nextcloud Site

  1. Enable mod_rewrite:
sudo a2enmod rewrite
  1. Create nextcloud.conf file in sites-available:
sudo nano /etc/apache2/sites-available/nextcloud.conf
  1. Paste the following configuration, updating your hostname/IPs as needed:
<VirtualHost *:80>
  DocumentRoot /var/www/nextcloud/
  ServerName yourcloud.example.com  

  Alias /nextcloud "/var/www/nextcloud/"

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

  <IfModule mod_dav.c>
    Dav off
  </IfModule>

  ErrorLog ${APACHE_LOG_DIR}/nextcloud-error.log
  CustomLog ${APACHE_LOG_DIR}/nextcloud-access.log combined
</VirtualHost>
  1. Enable the Nextcloud site:
sudo a2ensite nextcloud.conf
  1. Disable default site:
sudo a2dissite 000-default.conf  
  1. Restart Apache:
sudo systemctl restart apache2

Now let‘s complete Nextcloud‘s web installation wizard.

Step 7 – Web Installation Wizard

With everything configured, all that‘s left is running through Nextcloud‘s handy web installer.

  1. Visit your Pi hostname or IP address in browser, such as:

    http://yourcloud.example.com/nextcloud

  2. On first access it brings up the install wizard. Select your language.

  3. For the Data folder, set it as default at /var/www/nextcloud/data.

  4. Enter your Database user, password and name (created earlier).

  5. Set desired Nextcloud admin username and password.

  6. Wait several minutes for setup to complete.

All going well you should see the Nextcloud dashboard!

Some things you may wish to do from here:

  • Click top-right user icon -> Apps, to enable Calendar, Contacts and more
  • Setup External storage mounts
  • Add users
  • Explore Nextcloud theming options

And there you have it! You now have Nextcloud installed on a Raspberry Pi. From here you can start adding files and leveraging all of Nextcloud‘s excellent collaboration capabilities to keep your data safe under your control.

Some final tips on using Nextcloud:

  • Check available memory occasionally with df -h, upgrade SD card if needing more space
  • Backup Nextcloud data regularly
  • Keep Nextcloud version updated for latest features and security
  • Consider connecting an external USB hard drive for more storage space

Let me know in the comments if you found this beginner‘s Nextcloud on Raspberry Pi tutorial helpful!

Similar Posts