This article explains how to install Nextcloud on the Raspberry Pi. It has been tested with the latest version of Nextcloud (20.1 at the time of writing), but should work for future versions too. It has also been successfully tested on the latest Pi hardware, the Raspberry Pi 4, and on earlier Pi versions, and on the latest OS, Raspbian/Raspberry Pi OS 10 “Buster”. Article last updated 21/6/2021.
Nextcloud is an open source software package providing remote file sharing services, similar to Dropbox. But with Nextcloud, you retain ownership, security and control of the shared data. Nextcloud works well on a Pi 2, Pi 3 and especially a Pi 4 but will run very slowly on a Pi 1.
Note: This is a manual, step-by-step procedure. If you would rather do the installation automatically, please see my recent article Automatic Nextcloud Installation on Raspberry Pi, which explains how to install Nextcloud with 3 commands. It is the quickest and easiest way to get Nextcloud running. Both procedures achieve the same overall result, however.
My Raspberry Pi 4 was purchased from The Pi Hut in July 2019. It was installed with Raspberry Pi OS (Raspbian) 10 “Buster” by applying the image “2021-05-07-raspios-buster-armhf-lite.zip” downloaded from the raspberrypi.org downloads page.
Install Apache Web Server
Log into your Pi, either directly or through ssh from another system. I am using ssh. Update the software sources as follows.
$ sudo apt-get update
Install the Apache web server:
$ sudo apt-get install apache2
When asked if you want to continue, type “y” for “yes”. Apache will be installed along with a number of other packages.
In a browser, surf to the IP address of your Raspberry Pi. If you see a page entitled “Apache 2 Debian Default Page”, then Apache is running correctly on the Raspberry Pi. For example, my Pi is using IP address 192.168.1.99. So I start a browser on my PC and surf to http://192.168.1.99/. Alternatively, if you are using the Pi’s graphical desktop, you could start a browser directly on the Pi, eg. Chromium or Netsurf.
Install PHP and Associated Packages
A few packages will now be installed, including the latest version of PHP (7.3 at the time of writing).
Issue the following command. We will use the “-y” switch this time, which answers the “yes/no” question automatically.
$ sudo apt-get -y install php php-gd sqlite php-sqlite3 php-curl php-zip php-xml php-mbstring libapache2-mod-php
The software will be installed, which takes a few minutes.
Restart the web server now with:
$ sudo systemctl restart apache2
The command restarts Apache, but does not print out any messages.
Okay, the system is ready for Nextcloud to be installed. Download the latest version of the software as follows.
$ wget https://download.nextcloud.com/server/releases/latest.zip
Now move the Nextcloud package into place and unpack it:
$ sudo mv latest.zip /var/www/html $ cd /var/www/html $ sudo unzip -q latest.zip
Unzipping takes a minute or two.
If you are curious, the version can be be checked with:
$ grep VersionString nextcloud/version.php
$OC_VersionString = '21.0.2';
At the time of writing, (June 2021), the latest version is 21.0.2. To check the latest version online, have a look at the Nextcloud download page.
Create the Data Directory
You must create a “data” folder for Nextcloud and set permissions. Proceed as follows.
$ sudo mkdir -p /var/nextcloud/data $ sudo chown www-data:www-data /var/nextcloud/data $ sudo chmod 750 /var/nextcloud/data
Check the new directory with ls. You should see output like this, although of course your date and time will be different:
$ ls -ld /var/nextcloud/data drwxr-x--- 2 www-data www-data 4096 May 27 18:45 /var/nextcloud/data
Set Directory Owners
Next, set the correct ownerships on Nextcloud “config” and “apps” directories:
$ cd /var/www/html/nextcloud $ sudo chown www-data:www-data config apps
Configure Nextcloud for SQLite or MySQL
Nextcloud can use two kinds of databases: SQLite or MySQL. For a simple installation, with only one or two users, I would recommend SQLite, especially if you are using a P 2 or a Pi 3. It is more light weight and uses fewer resources than MySQL, and is therefore a good choice on Raspberry Pi hardware. To use SQLite, skip straight to the section below entitled “Configure Nextcloud”.
On the other hand, if you want to use MySQL instead, proceed to Install and Configure MySQL Database. MySQL is an appropriate choice for larger installations, if you plan to have more users, and particularly if you are using a Raspberry Pi 4.
Install and Configure MySQL Database
In order to use the MySQL database (also known as MariaDB), install it now, along with an extra php package:
$ sudo apt-get install -y mariadb-server python-mysqldb php-mysql
Set the MySQL root password and secure the database installation. Run the script /usr/bin/mysql_secure_installation. It will first ask you to enter the “current password for root”. No password has been set yet, so just press return to log in. Next, it asks if you want to set a root password. Answer “y“, choose a sensible password and make a note of it. Then answer “y” to all of the remaining questions, as below.
$ sudo /usr/bin/mysql_secure_installation Enter current password for root (enter for none): OK, successfully used password, moving on... Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y ... Thanks for using MariaDB!
Next, create a database for Nextcloud, and a database user. In the example I have called the Nextcloud user “ncuser” with a password of “raindrop”. For your own installation, choose a different user name and password. Don’t forget to take a note of both. Note that when running the following command, you will be asked to enter the root password that was set just above.
$ sudo mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 57 Server version: 10.3.29-MariaDB-0+deb10u1 Raspbian 10 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database nextcloud; Query OK, 1 row affected (0.001 sec) MariaDB [(none)]> create user ncuser; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> set password for ncuser = password("raindrop"); Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> grant all PRIVILEGES on nextcloud.* to ncuser@localhost identified by 'raindrop'; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> exit Bye
Restart the Apache web server once more with:
$ sudo systemctl restart apache2
The command restarts Apache, but does not print out any messages.
It is time to configure Nextcloud, either to use SQLite as a database, or, if you performed the commands in the last section, MySQL. Either way, proceed as follows.
In a browser, surf to your new Nextcloud web page. Use the URL:
http://your Pis IP address/nextcloud
For example, the address of my Pi is 192.168.1.99. So I go the the URL:
You should see a mostly blue login page. In the middle is a “Performance Warning” about SQLite. Ignore that. Near the top it says “Create an admin account”. Think of a user name and password and type them into the boxes provided. Then click on the “Storage and Database” drop-down. In the “data folder” box which appears, delete what is already there and replace it with “/var/nextcloud/data”
If you want to use SQLite as the database, then click on the “Finish Setup” button near the bottom of the page. Wait for a couple of minutes while Nextcloud completes the installation. During this time, Nextcloud creates more files and directories in our data directory, and it puts a SQLite database in there too.
If you want to use MySQL as the database, then where it says “Configure the database”, click on the button marked “MySQL/MariaDB”. Four new fields appear. Complete them as follows.
– for the database user, enter the name of the MySQL user you created above (“ncuser” in the example).
– for the database password, enter the accompanying password (“raindrop” in the example).
– for the database name, enter “nextcloud”
– leave “localhost” as “localhost”.
– then click on the “Finish Setup” button near the bottom of the page. Wait for a couple of minutes while Nextcloud completes the installation. During this time, Nextcloud creates more files and directories in our data directory, and it populates the MySQL database.
Completing the Configuration
While the installation runs, a dark blue “Recommended apps” box will appear, and a few Nextcloud add-ons are installed. It takes a few minutes, so be patient.
A few minutes later, you should see the Nextcloud intro page with the legend “Nextcloud Hub”. Click the right arrow to read more, or click the cross at the top right of the dialogue to dismiss it. You should now be looking at the main Nextcloud page. There you can see a few widgets, such as “Recommended files” and “Talk mentions”.
Congratulations! You have successfully installed Nextcloud!
Storing Nextcloud Data on a Separate Disk (Optional)
If you have a USB disk or thumb drive, you can use it to store the Nextcloud Data. In doing so, you might obtain more capacity for your data and/or improved performance.
First, mount your disk at a suitable location on the pi. Then proceed as follows. In this example, a thumb drive is mounted at “/disk1”. Move the Nextcloud data folder onto the drive as follows.
$ sudo mv /var/nextcloud/data /disk1/data $ sudo ln -s /disk1/data /var/nextcloud/data
The first command moves the data. The second creates a link from the original data location to the new one. Finally, if you have Nextcloud open in a browser, refresh the page. It should reappear after a few moments. Your data has now been moved onto the disk/thumb drive. Try dragging a large file into Nextcloud – you should see the disk access light flash as the data is written.
Securing the Site with TLS/HTTPS
If you want to secure your Nextcloud installation by converting it from HTTP to HTTPS, see my later article: How to Convert a Website from HTTP to HTTPS.
That is the end of the procedure for installing Nextcloud. Your Nextcloud installation should now be fully working. I hope this guide was easy to follow and not too long or fiddly.
Note: Prior to January 2018, this article included a section on moving the Nextcloud data directory for security purposes. It is no longer necessary. Alterations to the procedure above mean that the data directory is created at a secure location and does not need to be moved.
Note: In the past, this article also included a section explaining how to increase the Nextcloud file size upload limit. This is no longer needed, as recent Nextcloud versions no longer have the old file size limitation.
Appendix – A Note on Nextcloud vs Owncloud
Nextcloud was forked from ownCloud in June 2016. Since then, Nextcloud has increased in popularity and has become, for many users, the natural successor to ownCloud. Previously I wrote an article describing how to install and upgrade Owncloud. Now, I would recommend Nextcloud over ownCloud, except for large corporate users who might already have commercial agreements with ownCloud Inc. If you came here from the ownCloud article, thank you for your patience.