This article was revised and updated on 27th May 2017.
The Raspberry Pi’s low power consumption makes it well suited to the role of always-on web server. This post describes how to install Nextcloud onto the Pi. 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 and Pi 3 but will run very slowly on a Pi 1.
The below procedure describes how to install Nextcloud version 12.0.0, the latest stable version at the time of writing (27th May 2017), but it should work for later/future versions too.
NOTE: Nextcloud was forked from ownCloud in June 2016. It now seems that Nextcloud has largely taken over ownCloud’s role, 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 have come here from the ownCloud article, thank you for your patience. Okay, back to the procedure…
My Raspberry Pi 2 was purchased from RS Components in the UK. It was installed with Raspbian “Jessie” (Debian 8) by applying the image “2017-04-10-raspbian-jessie-lite.img” downloaded from the raspberrypi.org downloads page, where it is described as “Minimal image based on Debian Jessie”. The following procedure was then performed without any further pre-work (other than enabling ssh in the basic setup).
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. Netsurf.
Install PHP5 and Associated Packages
Nextcloud requires PHP 5 and few other packages. Install them as follows. We will use the “-y” switch this time, which answers the “yes/no” question automatically.
$ sudo apt-get -y install php5
$ sudo apt-get -y install php5-gd
$ sudo apt-get -y install sqlite
$ sudo apt-get -y install php5-sqlite
$ sudo apt-get -y install php5-curl
The software will be installed, along with other dependent packages.
Restart the web server now with:
$ sudo service apache2 restart
The command restarts Apache, but does not print out any messages.
Okay, the system is ready for Nextcloud to be installed.
Surf to the Nextcloud download page. At the top left is a section entitled “Get Nextcloud Server”. Click in the “Download” button just below that. A popup window opens. Click on the big blue “Download Nextcloud” button. Download the .zip file. Then copy it to the Raspberry Pi.
Alternatively (quicker), get the file on one step with this command on your Pi:
$ wget https://download.nextcloud.com/server/releases/nextcloud-12.0.0.zip
At the time of writing (27th May 2017), the latest version of Nextcloud is 12.0.0. The version, and the link to download it, might have changed by the time you read this article. If so, just change the link accordingly (check it at the download page above. For example in Firefox, right-click the big blue download button and select “Copy Link Location”. Then just paste the link into a wget command, as above).
Now move the Nextcloud package into place and unpack it:
$ sudo mv nextcloud-12.0.0.zip /var/www/html
$ cd /var/www/html
$ sudo unzip -q nextcloud-12.0.0.zip
Tip: if you are new to Linux. in case you were not aware, the tab key can be used to automatically enter file names, which saves on typing. For example, to enter the last command, I could have just typed “
sudo unzip -q next” and pressed the tab key. In fact I did. The whole file name is then inserted automatically.
Create the Data Directory
You must create a “data” folder for Nextcloud and set permissions. Proceed as follows.
$ sudo mkdir -p /var/www/html/nextcloud/data
$ sudo chown www-data:www-data /var/www/html/nextcloud/data
$ sudo chmod 750 /var/www/html/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/www/html/nextcloud/data
drwxr-x--- 2 www-data www-data 4096 May 27 18:45 /var/www/html/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
Create a Login for Nextcloud
In a browser, surf to your new Owncloud 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 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. Then click on the “Finish Setup” button.
…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. SQLite is a good choice if your Nextcloud implementation will be small with only a few users. It offers a good balance between speed and reliability. For larger installations, eg. in the enterprise, I would recommend using a MySQL database instead. Using MySQL is beyond the scope of this document.
Hey Presto! After a delay of 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.
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.
Below is a procedure for securing the Nextcloud data directory. I highly recommend it, especially if you are planning to make Nextcloud files accessible from the Internet. After that are instructions for increasing the Nextcloud upload limit.
Secure the Nextcloud Data Directory
This section assumes that you have installed Nextcloud by following the above procedure, using SQLite as the chosen database.
It is highly recommended to make Nextcloud more secure by moving the “data” directory to a more secure location. You might also want to move it for other reasons. For example, you could obtain more speed or capacity by moving the data directory onto a separate disk. Let’s move it to /var/nextcloud/data. That will prevent any unauthorized users from accidentally gaining access through the web browser.
Move the data directory:
$ sudo mkdir -p /var/nextcloud
$ sudo mv -v /var/www/html/nextcloud/data /var/nextcloud/data
Configure the new data location into Nextcloud. Using vi or another editor of your choice, edit the configuration file. Make a backup copy first, just in case there is a mistake with the edit:
$ cd /var/www/html/nextcloud/config
$ sudo cp -p config.php config.php.org
$ sudo vi config.php
Change this line:
'datadirectory' => '/var/www/html/nextcloud/data',
'datadirectory' => '/var/nextcloud/data',
Be careful not to delete the comma at the end of the line. Save the file and exit the editor.
Finally, update the SQLite database to reflect the new storage location. Open the database as follows:
$ sudo sqlite3 /var/nextcloud/data/owncloud.db
SQLite version 18.104.22.168 2014-10-29 13:59:56
Enter ".help" for usage hints.
Now modify the “oc_storages” table to point to the new data location. Be careful to type this line exactly as shown, including all signs and punctuation marks:
sqlite> update oc_storages set id="local::/var/nextcloud/data/" where id like '%local%';
Quit out of the database. Note the dot before the quit command:
Note: if you type something accidentally, and see this prompt: “ …>“, just type a semicolon (“;”) and press return to get back to the “sqlite>” prompt.
Now, in the browser, refresh the Nextcloud web page. You should see the same files and folders as before. That completes the securing of the Nextcloud data. Although it is still owned by www-data user, the Nextcloud data is now outside of the Apache root directory, and is therefore inaccessible to regular web requests.
Increase the Nextcloud Upload File Limit
Note: The following procedure does not seem to be needed in version 12 of Nextcloud. Older versions had a limit of 2MB in the size of file that could be uploaded. The limit seems to have been lifted in version 12, making the following unnecessary. It is left here in case anyone finds it useful, for example, if they are running an older version of Nextcloud.
Upload a file to Nextcloud as follows. Click on the square button containing a plus sign (“+”) near the top of the page. A drop down menu appears. Choose the first menu item, “Upload”, and select a file. The file will be transferred and you should see it appear in the Owncloud list of files. However, if the file was more than 2 MB in size, it will not upload. Instead a message will appear at the top of the screen – “Error uploading file “filename”: Total file size XX MB exceeds upload limit 2 MB”.
By default, the maximum size of file that can be uploaded is 2 MB, which is not enough for many people, Increase it as follows.
Edit the file /etc/php5/apache2/php.ini. You can use the “vi” editor, or another if you prefer:
$ sudo vi /etc/php5/apache2/php.ini
Change these two lines:
post_max_size = 8M
upload_max_filesize = 2M
post_max_size = 20M
upload_max_filesize = 20M
and save the file. Note: if you are having difficulty finding these settings in the file, use your editor’s search facility. In vi, you can search by pressing the slash key (“/”), then typing what you are searching for, such as “post_max_size”, then pressing enter.
$ sudo service apache2 restart
And refresh your browser page. The upload limit should have increased to 20 megabytes, which you can verify by trying another upload, as above.