top of page
  • Writer's pictureJoel

How to install Nextcloud on a Raspberry Pi

Updated: May 3, 2020



What you'll need

  • Raspberry Pi 3 B+ minimum

  • USB 3 caddy to house your HDD. You'll need one with a separate power supply

  • 1TB WD NAS HDD

  • A fast SD card with SD card adapter


*Note, here are the four products we recommend from Amazon:

 

Introduction

In this guide we'll show you how to setup Nextcloud on your Raspberry Pi 3. We will cover the following steps in an in-depth, methodical process:


  1. Installing Raspbian Buster Lite (non-gui, this will save RAM and CPU resources for your Nextcloud server)

  2. Installing Nextcloud on your Raspberry Pi

  • Mount and setup an external hard drive - Optional


Let's get started...

 

Installing Raspbian Buster Lite

  1. Start by going here to download the zipped version of Raspbian Buster Lite. Unzip the image file to your desktop.

  2. Now go here to download Win32DiskImager and install. Run Win32DiskImager and browse for the image from Step 1. Now click 'Write'

  3. Once the image has been written to the SD card, you will be able to access the root partition of the SD card from your PC. Open this up and create a file with the name 'ssh'. Ensure that there are no extensions to this filename.


Tip

Hopefully, you'll already know what SSH is. If you don't, this is the most brief explanation we can provide in the scope of this guide: SSH allows you to connect to another device over your network, instead of having to plug-in a keyboard, monitor and mouse to your Raspberry Pi. You can simply open a program like PuTTY and completely configure your Pi from your Laptop, PC, or even a mobile app. So that's what we did in Step 3; enabled SSH.


Connect to your Pi and login

Insert your newly imaged SD card and fire up your Pi. You can connect to your Raspberry Pi 3 using SSH. You will need to know the IP address of your Raspberry Pi 3 in order to do this. You should be able to find the IP address in your router's web based administration interface.


In this case, we'll use PuTTY to connect:


The default username is pi and the password is raspberry. You MUST change the default password as soon as you login, by running the following:

$ sudo raspi-config
 

Installing Nextcloud on your Raspberry Pi

Update the APT package repository cache with the following command:

$ sudo apt update

Now, install Apache 2 web server, PHP and all the required PHP libraries + tools with the following command:

$ sudo apt install mlocate apache2 libapache2-mod-php mariadb-client mariadb-server wget curl php php-common php-curl php-gd php-mbstring php-mysql php-xml php-zip php-intl php-apcu php-redis php-http-request

Once these have been installed, you'll need to create an Apache 2 host configuration file for Nextcloud. To do this use the following command:

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

Now, type or paste in the following lines, you don't need to change anything. Save the file by pressing <Ctrl> + x followed by Y and then press <Enter>.

<VirtualHost *:80>
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www/nextcloud
 Alias /nextcloud "/var/www/nextcloud/"
 
 <Directory "/var/www/nextcloud/">
 Options +FollowSymlinks
 AllowOverride All
 
 <IfModule mod_dav.c>
 Dav off
 </IfModule>
 
 Require all granted
 
 SetEnv HOME /var/www/nextcloud
 SetEnv HTTP_HOME /var/www/nextcloud
 </Directory>
 
 ErrorLog ${APACHE_LOG_DIR}/nextcloud_error_log
 CustomLog ${APACHE_LOG_DIR}/nextcloud_access_log common
 </VirtualHost>

You'll now need to create a new MariaDB database and a database user. Run the following command to connect to the MariaDB monitor:

$ sudo mysql -u root

You should now be logged in. Run the following command to create a database with the name nextcloud

MariaDB [(none)]> CREATE DATABASE nextcloud;

You'll now need to create a new MariaDB user called nextcloud and also set a password (in this case we'll use nextcloud for the password) for the new user with the following command:

MariaDB [(none)]> CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'nextcloud';

Next you'll have to assign all the required permissions of the database nextcloud to the MariaDB user nextcloud with the following command:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';

Run the following to apply the changes:

MariaDB [(none)]> FLUSH PRIVILEGES;

Now exit MariaDB monitor:

MariaDB [(none)]> exit

Next, navigate to the /var/www directory with the following command:

$ cd /var/www

It's now time to download Nextcloud, to do this, run the following:

$ sudo wget https://download.nextcloud.com/server/releases/latest-18.zip

Run the following command to unzip the Nextcloud archive:

$ sudo unzip latest-18.zip

Once that's done, you'll need to create a data directory for Nextcloud. We'll create the data directory in the /media/ directory:

$ sudo mkdir /media/data

Now, change the owner and the group of the directories and files within the /media/data and nextcloud/ directories to www-data with the following commands:


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

Next, grant owner permissions to the data folder:

$ sudo chmod -R 775 /media/data
 

Mount and setup an external hard drive - Optional

Assuming you have an NTFS drive we'll need to install a NFTS package by entering the following:

$ sudo apt-get install ntfs-3g -y

Now we need to get the GID, UID and the UUID as we'll need them later. This is so that the Pi will remember the drive even if we plug it into a different USB port. Enter the following command for the GID:

$ id -g www-data

Now to get the UID:

$ id -u www-data

We now need to obtain the UUID of the attached external hard drive:

ls -l /dev/disk/by-uuid

Copy the light blue letters and numbers of the sda2 (yours may vary) entry, usually located on the bottom. See below:


Now, we need to open the fstab file to input this information into the file system table:

$ sudo nano /etc/fstab

Add the following line to the bottom of the file, changing the UID, UID and the UUID with the values we obtained from above, save the file by pressing <Ctrl> + x followed by Y and then press <Enter>. (This should all be in a single line):

UUID=E4B22FE0B22FB648 /media/data auto nofail,uid=33,gid=33,dmask=0007,noatime 0 0
 

Next, enable the nextcloud.conf site configuration with the following command:

$ sudo a2ensite nextcloud.conf

Now, disable the default site configuration 000-default.conf with the following command:

$ sudo a2dissite 000-default.conf

Next, restart the apache2 service:

$ sudo systemctl restart apache2

You'll want to add apache2 (webserver) and mariadb (Nextcloud database) services to the system startup by running the following:

$ sudo systemctl enable apache2 mariadb

Now reboot your Pi:

$ sudo reboot

You now need to finish the Nextcloud setup via a web browser. Open a web browser and navigate to your Raspberry Pi address: http://192.168.0.10/nextcloud.

You should now see the Nextcloud configuration page.

Firstly, you'll need to create an administrator account and password, in this case we've chosen Admin for the username and Pa$$ for the password:



You'll also need to change the data folder directory, to the directory that you created earlier '/media/data'. We'll mount the external drive to this location later.




Then, enter the MariaDB details that you created earlier. The database name is nextcloud, the username is nextcloud and the password is nextcloud. Leave 'localhost' as it is. We've unticked the 'Install recommended apps', but that's just our preference. Click 'Finish setup' when you're done. This may take a few minutes to complete, depending on the speed of your SD card.



That's it. You now have a fully functioning Nextcloud server. You'll undoubtedly want to access your cloud from outside your home. To do this, there are a few more important things you need to do. Please follow each of the guides below:


  • Dynamic DNS - Allows you to access your cloud using a friendly web address, also ensures you can always access your cloud when your ISP dynamically changes your IP address.

  • SSL - Enables encryption between you and your Nextcloud server. This allows you to securely access your own cloud from anywhere in the world.

  • iNotifyScan - Without this, you won't be able to add files to Nextcloud via an SMB share. If you do, you won't see the files in the web interface or app.

  • SMB share - Creates a network share to enable easy access via your PC.

  • Redis LRU caching - Dramatically improve the performance of your Nextcloud server.


If you have any comments or questions, please feel free to email us.

2,050 views4 comments

Recent Posts

See All
bottom of page