Quantcast
Viewing latest article 5
Browse Latest Browse All 13

Automatic Nextcloud Installation on Raspberry Pi

Nextcloud is an open source software package providing remote file sharing services. It is similar to Dropbox. But with Nextcloud, you retain ownership, security and control of the shared data. This procedure describes how to build a working Nextcloud service using just 3 commands.  It has been tested on Raspbian Stretch and on the Raspberry Pi 4 / Raspbian Buster (this article updated 9/8/19)

Note: If you would rather do the installation manually, step-by-step, without the help of a script, please see my previous article Simple Nextcloud Installation on Raspberry Pi. It explains how to do the installation in detail, and provides more background information on Nextcloud. Both procedures achieve the same overall result, however.

Note: If you are running Raspbian Buster, then Nextcloud 16 will be installed.  For Stretch, it’s Nextcloud 15.

My Raspberry Pi 4 was installed with Raspbian 10 “Buster” by applying the image “2019-07-10-raspbian-buster-lite.zip” downloaded from the raspberrypi.org downloads page. Raspbian Buster was launched in June 2019, superceding the earlier Raspbian 9 “Stretch”. The following procedure works on both versions.  And it works in the Pi 4 and on earlier Pi hardware.

It is recommended to carry out this procedure on a fresh installation of Raspbian.

Note: If, having completed the procedure below, you wish to convert your Nextcloud installation from HTTP to HTTPS, please see my article How to Convert a Website from HTTP to HTTPS.

Download Ansible

Ansible” is an automation system for IT infrastructures. We will use it to set up Nextcloud. Install Ansible now.

$ sudo apt-get -y install ansible

Download the build_nextcloud script from Github:

$ wget https://raw.githubusercontent.com/webtaster/Nextcloud/master/build_nextcloud.yml

Install Nextcloud

Now, install and configure Nextcloud. As it runs, the following command will print various informational messages to the terminal, some of which are shown below. It should complete in about 15 minutes on Raspbian Stretch, or 5 minutes if you are using Raspbian Jessie (or Buster), so be patient.

Note that Nextcloud can use 2 type of databases: SQLite and MySQL. I would recommend SQLite, especially if your Nextcloud installation is to have only one or two users. SQLite is more lightweight than MySQL and uses fewer resources.  On the other hand, if you are planning a larger installation, and particularly if you are using a Pi 4, then MySQL would be an appropriate choice.

To install Nextcloud with SQLite, use this command.  Skip to the command below it if you want to use MySQL instead.

$ sudo date ; ansible-playbook --become -c local -i "localhost," build_nextcloud.yml
Sat 18 Nov 15:48:07 UTC 2017
PLAY [127.0.0.1] ***************************************************************
TASK [setup] *******************************************************************
ok: [127.0.0.1]
...

If you want to use MySQL, use the command below. It will install Nextcloud together with the MySQL database.

$ date ; ansible-playbook --become -c local -i "localhost," --extra-vars "DATABASE=mysql MYSQL_ROOT_PASSWORD=qwerty NCUSER_PASSWORD=raindrop" build_nextcloud.yml
Sat 18 Nov 15:48:07 UTC 2017
PLAY [127.0.0.1] ***************************************************************
TASK [setup] *******************************************************************
ok: [127.0.0.1]
...

Note that I have chosen “querty” as the MySQL root password, and for the ncuser password, “raindrop”. You should choose your own passwords instead, and keep a note of them, as they are needed below.

Once the command completes (either command above), you will have a basic Nextcloud installation running on your Pi. Proceed as follows to create an admin user and complete the configuration.

Create a User for Nextcloud

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: http://192.168.1.99/nextcloud

You should see a mostly dark 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. Note, however: do not press the [Enter] key while you are on this page. If you do, the system will think you have finished the whole page, and it will try to complete the configuration, and fail, because we have not entered some values yet. Quite likely it will say “can’t create or write into the data directory var/www/html/nextcloud/data“, or something similar. Rather then pressing [Enter] to move between fields, just click the mouse on the field you want to edit. If you run into a problem, just reload the page on your browser and start entering values again.

Just below the “password” box is a “Storage & database” drop-down. Click it to reveal the “Data Folder” box. In that, change the default “/var/www/html/nextcloud/data” to “/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 “ncuser”.
– for the database password, enter the NCUSER_PASSWORD that you chose above (“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.


Wait for a couple of minutes while Nextcloud completes the installation. After 2 minutes or so, you should see the Nextcloud intro page with the slogan “a safe home for all your data”. Click the cross at the top right of the dialogue to dismiss it. You should now be looking at the main Nextcloud “Files” page. There you can see a couple of folders, a Nextcloud MP4 video file, and a PDF Manual.

Congratulations!  You have just 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.

Conclusion

You now have a running Nextcloud installation. I hope this article has been helpful.


Viewing latest article 5
Browse Latest Browse All 13

Trending Articles