KevCaz's Website

I have already written elsewhere all the good that I think about Raspberry Pi. It is a fantastic project supported by a great community. I personally own a Rapsberry Pi model 3B and so far I have been using it for several small projects. For more than a year I have been thinking about running some small services on my Raspberry Pi, but never took the time to set it up. I finally took Christmas time to do it and I started with NextCloud. This post summarizes the different installation steps I went through to get a NextCloud server running on my Raspberry Pi. Note that I do not intend to provide a walk-through for the installation, I rather explain what needs to be done, give some commands and point to online documentation and tutorials. There are plenty of good tutorials available on line, notably the ones by Pi My Life Up, I don’t think they need to be duplicated!

Install Rapsberry Pi OS

For this project, I decided to re-install my Raspberry from scratch. Before doing so, I checked the version of Raspbian installed on it using inxi:

1
2
3
$ inxi -S
System:    Host: raspberrypi Kernel: 5.10.17-v7+ armv7l bits: 32 Console: tty 0 
           Distro: Raspbian GNU/Linux 10 (buster) 

Note that Raspbian is now referred to as Raspberry Pi OS, but is still a Debian image suited/optimized for Raspberry Pi devices. As I was looking for a way to download the image and install it on my microSD card (FWIW, a 64 Go one), I was very excited to learn that since March 2020, there is a new image utility, Raspberry Pi Imager, that makes the installation of Raspberry Pi seamless, so I used it! First, I downloaded the .deb file directly from the website and I installed it on my Debian machine as follows

1
$ dpkg -i imager_1.6.2_amd64.deb 

Then I opened and used Raspberry Pi Image which is very intuitive interface. That step actually took less time than I anticipated!

Basic settings

Once the microSD card ready, I inserted it in my Raspberry Pi and started the device. For this step, I use it as a personal computer, meaning that I used a keyboard, a mouse and a screen. That way I was able to enable SSH (this is the only step that is actually not needed for what follows, if you are only interested in Nextcloud you can skip the rest of this section) and to check out the graphical interface, which is pretty nice! I decided to have a look at the recommended software and I was happy to see that we can now install Visual Studio on a Raspberry Pi! I install it along with LibreOffice and Mathematica, I just thought that having some software installed wouldn’t hurt in case somebody needs to do some work on it at some point.

Visual Studio on my Raspberry Pi model 3B.

At that point, I realized than several tools were already installed, e.g.

1
2
3
4
5
$ python --version
Python 3.9.2

$ git version
git version 2.30.2

I only needed to install a few others. Again, these are not needed for the NextCloud installation presented below, but those are tools I use frequently, namely Docker, duf, Hugo, inxi, Julia and R:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 4 of these can be installed via apt-get 
$ apt-get install hugo inxi julia r-cran-bit64
[...]

# there is a bash script available online for docker 
$ curl -fsSL https://get.docker.com -o get-docker.sh
sh docker.sh

# duf is released on GitHub 
$ wget -O duf.deb https://github.com/muesli/duf/releases/download/v0.6.2/duf_0.6.2_linux_armv7.deb 
$ dpkg -i duf.deb 
$ rm duf.deb

# below are the versions installed
$ julia --version
julia version 1.5.3

$ hugo version
Hugo Static Site Generator v0.80.0/extended linux/arm BuildDate: 2021-02-09T18:47:48Z (raspbian 0.80.0-6)

$ R --version
R version 4.0.4 (2021-02-15) -- "Lost Library Book"
[...]

$ docker --version
Docker version 20.10.12, build e91ed57

$ duf --version
duf 0.6.2 (d1d2865)

# new version of the OS 
$ inxi -S
System:    Host: raspberrypi Kernel: 5.10.63-v7+ armv7l bits: 32 Console: tty 0 
           Distro: Raspbian GNU/Linux11 (bullseye) 

Note that in order to identify the right version of duf I needed, I checked out my CPU model with inxi:

1
2
3
inxi -C
CPU:       Info: Quad Core model: ARMv7 v7l variant: cortex-a53 bits: 32 type: MCP 
          Speed: 1200 MHz min/max: 600/1200 MHz Core speeds (MHz): 1: 1200 2: 1200 3: 1200 4: 1200 

This is how I knew that I needed to use the ARMv7 image of duf.

Connect to my Raspberry Pi via SSH

After the installation described above, I shut my Raspberry Pi down, and moved it next to my box, no keyboard, no mouse and no screen. And then I went back on my Debian machine. At this point I needed to locate my Raspberry Pi on my local network. Fortunately there are network tools to do so seamlessly, arp-scan is one of then that I was able to install using apt-get

1
$ apt-get install arp-scan

Then all I had to do was running the following command (I had to run it as super user)

1
$ arp-scan --localnet 

In the output I found something like this

1
192.168.1.25	b8:27:eb:f6:48:76	Raspberry Pi Foundation

actually there were two lines like this because the wi-fi was up (and I [disabled it] by editing disable the wi-fi by editing /boot/config). So there I knew that I could connect to my Raspberry Pi with the following command.

1
ssh pi@192.168.1.25

Note that instead of looking for the right IP address, it is possible to use multicast DSN (mDSN), on recent Raspberry Pi OS images, avahi is probably installed (see systemctl status avahi-daemon.service), otherwise it can be installed. Assuming avahi-daemon.service is up and running, then you can directly do

1
ssh pi@raspberrypi.local

The last thing I’ve done is that I added one of my public ssh keys to my Raspberry Pi to avoid typing my password in every time I connect to it. This is well-explained in a post by Py My Life Up:

  1. generate a ssh pair of keys with ssh-keygen,
  2. copy a public key to your Raspberry Pi using ssh-copy-id.

Using a static IP

This is super easy to do, but I honestly think that before doing that there are several terms you should know. I spent a fair amount of time reading about these, playing a bit with my home rooter (e.g. I change the range of dynamic IP), and it is worth it. At least I now have a better idea of what I am doing and why I needed to get a static IP. Fortunately there are a lot of good resources available on line (on Wikipedia for instance). Below is a list of term that are worth getting acquainted with.

I’d like to mentioned specific page on routersecurity.org that helped me a lot. Now, assuming that you have a basic understanding of the terms above and that you know the range of dynamic IP used by you DHCP, you can set a static IP chosen accordingly, it only requires to check /etc/resolv.conf and edit /etc/dhcpcd.conf, as explained on Pi My Life Up.

Setting NextCloud

I don’t actually need to write anything about this because the tutorial on Py My Life Up, “How to Setup a Raspberry Pi Nextcloud Server”, proposed an excellent tutorial that I basically followed. So if you want to set up your NextCloud server on your Raspberry Pi, just read this tutorial!

Well, … I can actually add a bit to the tutorial, because in my case I add a domain name, so I did not follow the last sections! Below are the section of the tutorial that I’ve followed

  1. Installing Apache and PHP
  2. Setting up a MySQL Database and User for Nextcloud (I had to install Mariadb first)
  3. Downloading Nextcloud on your Raspberry Pi
  4. Configuring Apache for Nextcloud
  5. Nextcloud Initial Setup
  6. Moving Nextcloud’s data folder
  7. Increasing Nextcloud’s max upload size

Once those were done, I went on my DSN provider, I created an A record to point to my public IP. Note that you can check your public IP by using websites that return your public IP, for instance https://wtfismyip.com/ and you can also access this info using commands, e.g.

1
2
# see https://askubuntu.com/questions/95910/command-for-determining-my-public-ip
wget -qO- https://ipecho.net/plain ; echo  

Then I opened ports 80 and 43,

1
$ sudo ufw allow 80,443/tcp

and then I set up the port forwarding on my rooter to my Rapsberry Pi. Last, I used Let’s Encrypt via certbot in the python3-certbot-apache (see this other post by Py My Life Up)

1
$ sudo certbot --apache

I answered the questions and then I got a congratulation message, which basically means that now I could be using HTTPS for the NextCloud web interface of my serve.

Then I did some configuration work: I created several users and add a security app, Two-Factor TOTP Provider as suggested in this youtube video (in French) which was also super useful for dealing with the installation.

Two remarks to conclude this section and this post. First, if you don’t want to go through all these steps and are just interested in having NextCloud up and running ASAP, you can use a preinstalled SD card images proposed by NextCloudPi. Second, all the steps described above led me to install the following packages:

1
2
3
4
$ sudo apt install apache2 php8.0 php8.0-gd php8.0-sqlite3 php8.0-curl \
  php8.0-zip php8.0-xml php8.0-mbstring php8.0-mysql php8.0-bz2 php8.0-intl \
  php-smbclient php8.0-imap php8.0-gmp libapache2-mod-php8.0 mariadb-server \
  python3-certbot-apache