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 10.0.1, the latest version at the time of writing (20th Nov 2016), 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 “2016-09-23-raspbian-jessie.img” downloaded from the raspberrypi.org downloads page, where it is described as “Raspbian Jessie with Pixel”. 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
Owncloud requires PHP 5 and few other packages. Install them as follows.
$ sudo apt-get install php5
$ sudo apt-get install php5-gd
$ sudo apt-get install sqlite
$ sudo apt-get install php5-sqlite
$ sudo apt-get 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-10.0.1.zip
At the time of writing (20th November 2016), the latest version of Nextcloud is 10.0.1. 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 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-10.0.1.zip /var/www/html
$ cd /var/www/html
$ sudo unzip -q nextcloud-10.0.1.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. We will put the data in /var/nextcloud/data, because it is a secure location. 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 Nov 20 14:41 /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 competes the installation. During this time, Nextcloud creates more files and directories in our data directory, and it puts a database in there too.
Hey Presto! After a after a short delay, 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
It is highly recommended to make Nextcloud more secure by moving the “data” directory to a secure location. Let’s move it to /var/owncloud/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.
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.
Increase the Nextcloud Upload File Limit
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.