DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

NextCloud on Pi 2/3 Start to finish Guide

Sun Sep 25, 2016 1:46 am

First a little about myself. I don't normally do write-ups but after spending 4 days googling/IRC Chatting/reinstalling I compiled a complete guide to install Nextcloud on the PI so not only does it run off an external hard drive (Space and Speed), but it has all the protection needed to be safe to run and trust worthy. I am by no stretch a Linux SuperUser. I'm more like a geek that loves to learn new things. If anyone finds any issues in the guide or has ideas to make it better please feel free to contact me and I'll do what I can to make it happen.

That being said I take no responsibility if you cause damage or have issues with your pi afterwards. Again this is a collections of info put in order for an easy smooth install.

Any real superuser feel free to make this a script and send it out should make the process much easier for people that way.

This is turn key. When you are done you will have a complete install with all the basic functions enabled and ready.

This tutorial uses the following files and versions. I did the best I could to make sure I worked with everything as up to date at possible at the time of this writing. (Make it a total pain to complete.) If done correctly you can have one up if a couple hours instead of days like to took me.

2016-05-27-raspbian-jessie/NextCloud 10.0.0.0/PHP7/Apache2/MariaBD version?

A couple preinstall things you can do to make life easier later are. If your router supports static mapping via DHCP thats really handy. Otherwise you will have to set one up on the pi yourself. I will not go in to that on this tutorial. You will need a named address so you can get a SSL Cert I use www.no-ip.com (Only because I've been with them for years.) make sure it points to your house . If you have a decent router it will support a client with them and keep that address point correct. If yours doesn't support that you can always get a linux or windows client to do that for you. If you don't have a computer that stays in all the time I would install it on the Pi it self and the site has instructions to do so. Next if your router supports DNS Resolver/Forwarder set it up to forward all internal requests for the external Named site to point to the internal address. This solves Many problems with the Cert later. If your router doesn't do these things check out http://dd-wrt.com/site/support/router-database and see if you can upgrade your router to a better OS.


Installation.

Download the image and write it to your card. (I assume if you are attempting this you know how to do that if not https://www.raspberrypi.org/documentati ... /README.md.)

Insert the SD in the Pi 2/3 Hook up all the cables except power. (This tutorial is made to work with a wired connection on wifi you may experience slower rates or disconnectivity issues. If you want wifi feel free to google that yourself first before continueing)

If you can have the external hard drive wiped of all partitions as we will create them in the tutorial. If not we can delete the partitions in linux. (Just easier to use GPARTED -=Linux=- or diskpart -=windows=-)

On first boot (while you will do most of this from SSH I recommend using the GUI for this part) run Raspbian Config.
Setup all your main settings Keyboard/Timezone/Location ect. after a reboot you can make this a headless box if you like.
I however like to have TOP Running in a terminal window to see the usage of the processor and ram. Doesn't Hurt.

If possible use the SSH Client to log in from a computer for the rest of this tutorial. If you can't or prefer not to you can do all the work from with in the terminal but when writing the script you will have much more typing to do. Also is you can't cut and paste the command in to the terminal you might not get the intended results.

once in lets get admin status with the following command

Code: Select all

sudo su
just in case there are partitions on this drive you should try this command if it errors you good to go if not good thing we did it.

Code: Select all

umount /dev/sda1
umount /dev/sda2
umount /dev/sda3
umount /dev/sda4
If you had partitions you must delete them in fdisk before you create the partition. If you previously deleted the parts on the disk you can skip this step.

Code: Select all

fdisk /dev/sda
Press d
if it asks for a partition number you must repeat the process until the drive is wiped of all partitions
then press w
Now lets partition the disk for its new use. After pressing N if it asks Primary or secondary press P if not just follow the instructions as listed.

Code: Select all

fdisk /dev/sda
press n
press 1
press enter 2x
press w
Now lets format the drive for use

Code: Select all

mke2fs -t ext4 -L rootfs /dev/sda1
now mount the new partition.

Code: Select all

mount /dev/sda /mnt
We need a backup tool for the next part

Code: Select all

apt-get install rsync
Mirror the current rootfs to the new location Must use sudo or it will create a loop

Code: Select all

sudo rsync -axv / /mnt
Back up your startup file

Code: Select all

cp /boot/cmdline.txt /boot/cmdline.orig
edit startup file

Code: Select all

nano /boot/cmdline.txt
You need to edit 2 parts of this line do not make any other changes. Change the root= to /dev/sda and at the end add rootdelay=5
in the end my line looks like this

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait rootdelay=5
Now we need to edit a file on the new location

Code: Select all

nano /mnt/etc/fstab
make the changes so it looks like the following.

Code: Select all

proc            /proc           proc    defaults          0       0
/dev/sda1       /               ext4    defaults,noatime  0       1
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
now we need to reboot to load on the new drive.

Code: Select all

shutdown -r now
You will need to log back in to the system with your SSH if the box still has a head watch for errors on start if something went wrong you will know pretty quickly. Otherwise the boot process is about 30 seconds.

once in the box regain root with this

Code: Select all

sudo su
enlarge the swap now that we have TONS of space

Code: Select all

nano /etc/dphys-swapfile
change 100 to 512

Run the following to make use of the change

Code: Select all

sudo dphys-swapfile setup
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
for some reason you must still use sudo here even with root access. (don't know why didn't work for me with out it)

get all the system updates

Code: Select all

apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
rpi-update
apt-get autoremove
Reboot

SSH back in and get root

Code: Select all

sudo su
Install Apache2

Code: Select all

apt-get install apache2 -y
Install PHP7

Code: Select all

nano /etc/apt/sources.list
add the following line

Code: Select all

deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
Make a new file thats needed to continue

Code: Select all

nano /etc/apt/preferences
paste in the following

Code: Select all

Package: *
Pin: release n=jessie
Pin-Priority: 600
Run all of the following command in order

Code: Select all

apt-get update
apt-get install -t stretch php7.0 php7.0-curl php7.0-gd php7.0-fpm php7.0-cli php7.0-opcache php7.0-mbstring php7.0-xml php7.0-zip -y
apt-get install php7.0-APC -y
apt-get install mysql-server php7.0-mysql -y
a2enmod proxy_fcgi setenvif
a2enconf php7.0-fpm
service apache2 reload
apt-get install libxml2-dev php-zip php-dom php-xmlwriter php-xmlreader php-gd php-curl php-mbstring -y
a2enmod rewrite
service apache2 reload
apt-get install mariadb-server -y
cd /var/www/html
nano index.html
Add the following line to the top where "MY.NEXTCLOUD.NAMEDADDRESS.COM" should be the address you created earlier.

Code: Select all

<meta http-equiv="refresh" content="0; URL='http://MY.NEXTCLOUD.NAMEDADDRESS.COM/nextcloud'" />
install Nextcloud

Code: Select all

cd /var/www/
wget https://download.nextcloud.com/server/releases/nextcloud-10.0.0.zip
unzip nextcloud-10.0.0.zip
rm nextcloud-10.0.0.zip
cd /
mkdir CloudDATA
cd /home/pi
nano permissions.sh
Paste in the following

Code: Select all

#!/bin/bash

ocpath='/var/www/nextcloud'

htuser='www-data'

htgroup='www-data'

rootuser='root'


printf "Creating possible missing Directories\n"

mkdir -p $ocpath/data

mkdir -p $ocpath/assets

mkdir -p $ocpath/updater


printf "chmod Files and Directories\n"

find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640

find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750


printf "chown Directories\n"

chown -R ${rootuser}:${htgroup} ${ocpath}/

chown -R ${htuser}:${htgroup} ${ocpath}/apps/

chown -R ${htuser}:${htgroup} ${ocpath}/assets/

chown -R ${htuser}:${htgroup} ${ocpath}/config/

chown -R ${htuser}:${htgroup} ${ocpath}/data/

chown -R ${htuser}:${htgroup} /CloudDATA/

chown -R ${htuser}:${htgroup} ${ocpath}/themes/

chown -R ${htuser}:${htgroup} ${ocpath}/updater/

chown -R ${htuser}:${htgroup} /tmp


chmod +x ${ocpath}/occ


printf "chmod/chown .htaccess\n"

if [ -f ${ocpath}/.htaccess ]

then

 chmod 0644 ${ocpath}/.htaccess

 chown ${rootuser}:${htgroup} ${ocpath}/.htaccess

fi

if [ -f ${ocpath}/data/.htaccess ]

then

 chmod 0644 ${ocpath}/data/.htaccess

 chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess

fi
make it a executable and run it

Code: Select all

chmod +x permissions.sh
sudo ./permissions.sh
Configure Apache2

Code: Select all

cd /etc/apache2/sites-available
nano nextcloud.conf
Paste in the following

Code: Select all

Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
 Options +FollowSymlinks
 AllowOverride All

<IfModule mod_dav.c>
 Dav off
</IfModule>

SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud

</Directory>
Do the following commands

Code: Select all

ln -s /etc/apache2/sites-available/nextcloud.conf /etc/apache2/sites-enabled/nextcloud.conf
a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime
a2enmod ssl
a2ensite default-ssl
service apache2 reload
Setup the DataBase

Code: Select all

mysql -u root -p
enter the following commands Where it says "PASSWORD" enter a password for the database to use DON'T FORGET IT well need it later.

Code: Select all

CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON nextcloud.* TO nextclouduser@localhost;
EXIT
Setup SSL

Code: Select all

apt install git -y
cd /etc
git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
sudo ./letsencrypt-auto
crontab -e
Enter the following line at the bottom of the file

Code: Select all

* 1 * * 1 /etc/certbot-auto renew --quiet
Now were ready to login to the server to generate the configfile we need to edit
open a browse and go to the named address you created earlier it should take you to your cloud.
Enter the name and password you will use as the site administrator
Change the Data Folder to the following

Code: Select all

/CloudDATA
the data base info is as follows with PASSWORD being the password you used for the DataBase

Code: Select all

nextclouduser
PASSWORD
nextcloud
Enable Mem Cache most guides say this is optional it really isn't just do it

Code: Select all

sudo nano /var/www/nextcloud/config/config.php
There before ); insert

Code: Select all

'memcache.local' => '\OC\Memcache\APC',
Clean the disk from all the mess
apt-get clean

Set File size limit

Code: Select all

cd /var/www/nextcloud
nano .htaccess
find the line that says php_value upload_max_filesize 512M and the line below it that says php_value post_max_size 512M
Change both to the size you want if in Gigs use a G instead of the M

Code: Select all

nano .user.ini
Find upload_max_filesize=512M and post_max_size=512M
Change these to the same size you used before and don't forget to change to a G if in Gigs

Now harden the box as much as I know how by preventing Man in the Middle Attacks

Code: Select all

cd /etc/apache2
nano apache2.conf
at to bottom of the file add the following

Code: Select all

<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</IfModule>
Reboot

Code: Select all

shutdown -r now
When it come back up go to your browser and login to go to app page choose productivity and pick documents, now go to admin then additional settings and setup to use the libreoffice (Top option at the time of this writing) click save and test

Done and Enjoy. Everything is all set and you can configure the rest to your liking on the site.
Last edited by DrClaw22000 on Tue Sep 27, 2016 3:06 am, edited 1 time in total.

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Tue Sep 27, 2016 1:25 am

The previous Errors have been corrected. A Friend pointed out errors.

Claw

Brus
Posts: 1
Joined: Mon Sep 26, 2016 7:08 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Tue Sep 27, 2016 7:36 am

"MY.NEXTCLOUD.NAMEDADDRESS.COM" you said it has been created earlier but I have not created it. How to create it ? I run all commands successfully before this step. Please help me.

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Tue Sep 27, 2016 12:20 pm

Go to http://www.noip.com and sign up. You just need to have an named address. I hope you already forwarded your ports 80 and 443 to your Pi on your router. Brfore the instructions You will see I talked about some things that you need to do before your setup your pi. Let me know if you need help with that. I have TeamSpeak or we could meet on IRC. Let me know.

Claw

User avatar
ScoobyDoo
Posts: 107
Joined: Wed Apr 04, 2012 2:52 pm
Location: Staffordshire, UK

Re: NextCloud on Pi 2/3 Start to finish Guide

Tue Sep 27, 2016 1:50 pm

Thanks for the detailed writeup.

I see this in now in dietpi which makes everything so much simpler.

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Tue Sep 27, 2016 2:24 pm

Dietpi? A mag? The write up uses all the newest available versions helping with security. Glad people are getting use out of it.

DrClaw

Avma
Posts: 3
Joined: Tue May 27, 2014 8:54 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Wed Sep 28, 2016 5:03 pm

Great guide!

I must be doing something wrong, got stuck right at the beginning trying formatting my 2TB HDD and ended up with a 6.9Mib propitiation?! I went through the process twice with the same results. (i never formatted a HDD on raspberry pi or Linux before :oops: )

Can you pleas point out what am i missing here?

Many thanks
Avi
Attachments
Capture1.JPG
Capture1.JPG (45.29 KiB) Viewed 50426 times

User avatar
rpdom
Posts: 11860
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: NextCloud on Pi 2/3 Start to finish Guide

Wed Sep 28, 2016 7:50 pm

You still have another partition on the drive (it only gives you the option of creating 1, 3 or 4 because partition 2 already exists).

Try the "p" option to list the current partitions.

You can then use the "o" option to clear the partition table before starting to create your new partition.

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Thu Sep 29, 2016 5:47 am

Avma wrote:Great guide!

I must be doing something wrong, got stuck right at the beginning trying formatting my 2TB HDD and ended up with a 6.9Mib propitiation?! I went through the process twice with the same results. (i never formatted a HDD on raspberry pi or Linux before :oops: )

Can you pleas point out what am i missing here?

Many thanks
Avi
Sorry it's taken me so long to respond. Your issue is size. You need to use GPT. Fdisk won't do that. The easiest way is to download gparted live cd boot it on a different system. And make the partition with that.

I'm typing from my phone so I won't go into more detail now. If you need more help let me know well setup a time to chat on my TeamSpeak server.

Claw

Avma
Posts: 3
Joined: Tue May 27, 2014 8:54 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Thu Sep 29, 2016 8:50 am

Great! Thanks, that worked pretty well. Got my 2T disk space back, so i can continue installing nextcloud now...
Capture2.JPG
Capture2.JPG (18.37 KiB) Viewed 50276 times

Avma
Posts: 3
Joined: Tue May 27, 2014 8:54 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Thu Sep 29, 2016 11:45 am

Its up and running!

one again, many thanks for this excellent guide.

My Best Regards
Avi

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Thu Sep 29, 2016 12:02 pm

I'm glad it's getting use. I'm also surprised someone put a 2Tb drive on a Pi. That's awesome.

Enjoy let me know your experience.

austinpavlas
Posts: 8
Joined: Sun Oct 02, 2016 2:55 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Mon Oct 03, 2016 12:18 am

I have been having trouble mounting my new drive. Everytime I attempt to do so I get this error.

Code: Select all

mount:  wrong fs type. bad option. bad superblock on /dev/sda.
missing codepage or helper program, or other error.
Thank you for the great guide. I hope I can successfully do this later eventually.

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Mon Oct 03, 2016 1:01 am

austinpavlas wrote:I have been having trouble mounting my new drive. Everytime I attempt to do so I get this error.

Code: Select all

mount:  wrong fs type. bad option. bad superblock on /dev/sda.
missing codepage or helper program, or other error.
Thank you for the great guide. I hope I can successfully do this later eventually.
A few questions might help me solve this...

1.) What is the size of the drive?

2.) Did Fdisk have any errors while creating new partitions.

3.) Did you get an error when unmounting before using Fdisk?

4.) Did you try setting up the partition before hand in GParted Live CD?

Claw

austinpavlas
Posts: 8
Joined: Sun Oct 02, 2016 2:55 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Mon Oct 03, 2016 4:43 am

DrClaw22000 wrote:
austinpavlas wrote:I have been having trouble mounting my new drive. Everytime I attempt to do so I get this error.

Code: Select all

mount:  wrong fs type. bad option. bad superblock on /dev/sda.
missing codepage or helper program, or other error.
Thank you for the great guide. I hope I can successfully do this later eventually.
A few questions might help me solve this...

1.) What is the size of the drive?

2.) Did Fdisk have any errors while creating new partitions.

3.) Did you get an error when unmounting before using Fdisk?

4.) Did you try setting up the partition before hand in GParted Live CD?

Claw

It is a 1tb Seagate ultra slim drive.
I had no other errors before hand.
I did clean the drive using diskpart on windows before hand, but did not try and partition or format.

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Mon Oct 03, 2016 4:49 am

Get the version appropriate to your system and do the partition manually

http://gparted.org/download.php

Sending from my phone so might have typos

After that skip the fdisk part. You still need to unmount and remount to /mnt
Let me know what happens

Claw

austinpavlas
Posts: 8
Joined: Sun Oct 02, 2016 2:55 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Wed Oct 05, 2016 2:37 am

DrClaw22000 wrote:Get the version appropriate to your system and do the partition manually

http://gparted.org/download.php

Sending from my phone so might have typos

After that skip the fdisk part. You still need to unmount and remount to /mnt
Let me know what happens

Claw

Should I mount it using?

mount /dev/sda /mnt

or mount /dev/sda1 /mnt

Thanks for all the help Im not great at this.


austinpavlas
Posts: 8
Joined: Sun Oct 02, 2016 2:55 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Wed Oct 05, 2016 7:28 am

I finsihed the guide and had the server working great until I restart my pi. After restarting my pi when I go to my webpage I can see the apache2 default home page for second, then it redirects to a page that says my web address is unreachable. Not sure what went wrong.

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Wed Oct 05, 2016 12:18 pm

That's a tough one. I will probably need to work with you to figure that out. I have a public TeamSpeak server voice.clawfest.com. I'm not sure what time I'll be available but if you have the time let's do it. We can post or findings here afterwards. Let me know if your interested. The software you need is free at TeamSpeak.come.

Thanks
Claw

austinpavlas
Posts: 8
Joined: Sun Oct 02, 2016 2:55 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Thu Oct 06, 2016 5:55 pm

DrClaw22000 wrote:That's a tough one. I will probably need to work with you to figure that out. I have a public TeamSpeak server voice.clawfest.com. I'm not sure what time I'll be available but if you have the time let's do it. We can post or findings here afterwards. Let me know if your interested. The software you need is free at TeamSpeak.come.

Thanks
Claw
I got it figured out. For reason mysql had disabled itself and needed to be uninstalled and reinstalled then all worked great. Thanks for this amazing up to date guide.

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Thu Oct 06, 2016 7:27 pm

No problem. After all the work I put in to making the server I thought it would be nice to share and try and save people the time. It's nice to give back and see it being used.

Claw

cislom
Posts: 1
Joined: Mon Oct 10, 2016 1:27 am

Re: NextCloud on Pi 2/3 Start to finish Guide

Mon Oct 10, 2016 1:29 am

Thanks for the awesome job!

I got a Nextcloud Box, but this is so much better! I have Zero Linux experience and this really helped out a lot.

Thanks Again!

IGotDT
Posts: 4
Joined: Sat Apr 18, 2015 8:21 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Mon Oct 10, 2016 2:13 pm

Everything seemed to go smoothly until I tried to create a new user. I get the following error in my apache log:

Code: Select all

[Mon Oct 10 09:39:28.932574 2016] [proxy_fcgi:error] [pid 1780] [client 192.168.1.166:52966] AH01071: Got error 'PHP message: PHP Fatal error:  Couldn't find implementation for method \x06::__tostring in Unknown on line 0\n'
[Mon Oct 10 09:39:47.825243 2016] [proxy_fcgi:error] [pid 1780] [client 192.168.1.1:52979] AH01071: Got error 'PHP message: PHP Fatal error:  Couldn't find implementation for method \x06::__tostring in Unknown on line 0\n'
[Mon Oct 10 09:40:32.477223 2016] [proxy_fcgi:error] [pid 1782] [client 192.168.1.166:53002] AH01071: Got error 'PHP message: PHP Fatal error:  Couldn't find implementation for method \x06::__tostring in Unknown on line 0\n'
For reference of the IPs: 166 is my desktop, 147 is the RPi, and 1 is obviously my router.

I have been able to resolve the problem by restarting php with

Code: Select all

sudo service php7.0-fpm restart
. Again, evereything works until I attempt to create a new user. I can install apps, create and edit documents, transfer files, etc. But the moment I click "Create" the whole server crashes. Any advice?

DrClaw22000
Posts: 46
Joined: Sat Sep 24, 2016 11:15 pm

Re: NextCloud on Pi 2/3 Start to finish Guide

Fri Nov 04, 2016 9:36 pm

Sorry for such a late reply. I have no idea why the email didn't notify me that someone was sending posts. Any future people with issues please send requests to me via skype @ Claw22000 / Steam @ Dr. Claw / Origin @ Claw22000 / and Teamspeak on my private server everyone is welcome to use @ voice.clawfest.com. I am not always on teamspeak but if you need help you can message me and well get on together. I can then talk you through the issues your having.

As for the current issue I need some more information as to whats going on to be able to tell you what to do to fix it. Please let me know when you have read this since it has been so long and I don't know if you are still trying to solve this.

Thanks

Claw

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 19 guests