Setting up NextCloud on Raspberry Pi 3

Originally published February 4, 2017 (a work in progress)

I have been frustrated by the lack of sufficient network storage space offered by the university for purposes of research (50 GB of Box.com storage space is allowed to JHU users). I would also rather not end up paying ~$100/year of my own money for something like Dropbox or google drive. As a result, I aimed to setup my own server running NextCloud (successor to OwnCloud) running from a Raspberry Pi 3 with as an alternative. Since this is a rather new experience for me, I thought I may as well document it.

This guide is largely informed by the guides already written by PiMyLife for setting up a Raspbian OwnCloud server and UnixEtc for specifically setting up NextCloud. I am obligated the thank them greatly, as I never would have gotten through this without the help.

 

Purchase – ~$60 total since I already owned an external hard drive

  1. Raspberry Pi 3  – $43 for charger included from Canakit
  2. Micro SD card – $12 for 32GB at amazon – class 10 is your best bet and 32GB is around the best price performance at the moment
  3. Case – $6
  4. External hard drive – with charger – so avoid portable hard drives. (Already owned)

Install Etcher

You’ll want to be able to connect the Pi to a monitor via HDMI, which I highly recommend for the initial setup. Having a second monitor or laptop primary monitor is also very helpful.

Once booted into Raspbian open up preferences via GUI.

  1. Change password (default is raspberry) to make it more secure.
  2. Expand file system to entire disk space
  3. Enable SSH under interfaces
  4. Set locale to your country
  5. Set keyboard
  6. Set wifi if you are setting up at home. If you’re connecting to university wifi I recommend using Ethernet as the Pi 3 seems incapable of connecting to the enterprise wifi network setup at Hopkins.
  7. Reboot to allow changes to take effect

Next, open terminal and run command below to determine the Pi’s IP address for connecting via ssh. It should be something like 10.

sudo ifconfig

With ssh you should now be able to connect via Mac terminal or ssh terminal in Windows like PuTTY . This enables you to control the Pi from the command line and if you’re anything like me it’s easier to work from your primary computer in this fashion.

If you end up having to re-do the installation, you’ll have to reset the ssh certificate. Use the command below to clear the key to eliminate the error message.

ssh-keygen -R *your IP, ex. 192.168.3.10*

So via ssh or in Raspbian’s OS terminal, run the following commands to update. Say y for yes

sudo apt-get update

sudo apt-get upgrade

Then install Apache web server with the following command. Click y for yes to install.

sudo apt-get install apache2

Then on either computer try going to your Pi’s default IP and you should see the message below showing that Apache installed correctly. The IPV4 address should be something like http://192.168.1.99 or http://10.113.92.120

apache

Following confirmation that Apache installed, install php5 via commands below

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

Next, restart Apache. I recommend also rebooting the entire pi as well

sudo service apache2 restart

sudo reboot

Next, install NextCloud. Current version was 11.0.1 when I wrote this, but you can check their website for later versions that should be able to be installed in the same manner. Following commands move it to the correct folder and unzip the download.

wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip

sudo mv nextcloud-11.0.1.zip /var/www/html

cd /var/www/html

sudo unzip -q nextcloud-11.0.1.zip

Then, quoting the already written guide directly for this part

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: 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. 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.

I should note that when I was trying this step, UBlock Orgin (default install on chromium in Raspbian and running on Chrome for my laptop) was blocking access to NextCloud, so you may need to either disable UBlock Origin or use an alternative browser in order to reach the nextcloud login page. This site brought my attention to the problem

Next, you’ll want to increase the max file size you can upload. Since you’re going to be editing the .ini file, I recommend backing it up temporarily to the Pi’s desktop with the following command.

cp /etc/php5/apache2/php.ini /home/pi/Desktop/

Next, edit the php.ini file with the following command to open it in the nano editor

sudo nano /etc/php5/apache2/php.ini

Find the following lines with CTRL+W and edit, then type CTRL+O to rewrite and hit enter to save. The hit CTRL+X to exit. Note – NextCloud is currently limited to 2000MB max file size.

Change these two lines:
post_max_size = 8M
upload_max_filesize = 2M

to:

post_max_size = 2000M
upload_max_filesize = 2000M

Then restart Apache

sudo service apache2 restart

Connecting External Hard Drive

Reformat drive for NTFS in windows or MacOS and connect to the Pi. Then run the following commands in Raspbian to create the folders for your actual storage drive and be able to load the drive. lsblk lists the disks. You should see your external drive, otherwise it’s not formatted correctly.

sudo apt-get install ntfs-3g

sudo mkdir /var/nextcloud/

sudo mkdir /var/nextcloud/data/

lsblk
  1. UUID=8c0a7e15-a81a-4f59-9e30-7fabf14fff5c /var/nextcloud/data/ auto nofail,uid=33,gid=33,umask=0027,dmask=0027,noatime 0 0

 

Once you have everything set up like you like, I recommend creating a clone of the Raspbian drive so you can restore if you need to in the future. Guide for windows is described here and MacOS here or Linux here.

My specific mac command:

sudo dd if=/dev/rdisk3 bs=1m | gzip > /users/davidwilson/desktop/apache_pi_backup.gz

This takes quite a while to run since you’re compressing many GBs of data, so you can check that it’s still functioning in terminal on Mac with CTRL+T

 

I found it very frustrating not to be able to navigate the root folders in the Raspbian file system, so you can either sign in as root or grant access by downloading gksu and then activating it for a file system window.

sudo apt-get install gksu

 

To be continued – maybe

Advertisements

One thought on “Setting up NextCloud on Raspberry Pi 3”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s