Installing NextCloud With Docker Scripts

Reading time ~4 minutes

Installing NextCloud With Docker Scripts

Installing NextCloud With Docker Scripts

In this article we will see an easy way to install and maintain nextcloud in a VPS and in RaspberryPi.

1 Installing nextcloud in a VPS

Let's assume that we have a VPS and a domain like nc.example.org.

1.1 Install docker

We can install docker-ce like this:

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

1.2 Install docker-scripts

Docker-Scripts is a shell script framework for Docker. Install it with these commands:

apt install m4 git
git clone https://gitlab.com/docker-scripts/ds /opt/docker-scripts/ds
cd /opt/docker-scripts/ds/
make install
ds
ds -h

1.3 Install web server proxy

We will need wsproxy for getting a letsencrypt SSL certificate. We can install it like this:

ds pull wsproxy
ds init wsproxy @wsproxy
cd /var/ds/wsproxy/
vim settings.sh
ds make

1.4 Install nextcloud

Now we can install a nextcloud container like this:

ds pull nextcloud
ds init nextcloud @<nc.example.org>
cd /var/ds/<nc.example.org>/
vim settings.sh
vim apps.txt
ds make

Make sure to replace <nc.example.org> with your domain and also to set proper values on settings.sh. To make an automatic installation, uncomment ADMIN_USER and ADMIN_PASS and change the value of the password.

Finally, open https://nc.example.org in browser.

1.5 Install a DB server (optional)

If there are many users that will use this instance of nextcloud, using a DB like mysql or postgresql may help to make things faster and more efficient. You can install a mariadb container like this:

ds pull mariadb
ds init mariadb @mariadb
cd /var/ds/mariadb/
vim settings.sh
ds make

Then uncomment the DB section on /var/ds/<nc.example.org>/settings.sh and build it again:

cd /var/ds/<nc.example.org>/
ds make

1.6 Sending notifications

To send notifications you can use GMail as an SMTP server. See these instructions and set properly GMAIL_ADDRESS and GMAIL_PASSWD on settings.sh: https://www.lifewire.com/get-a-password-to-access-gmail-by-pop-imap-2-1171882 Then run:

cd /var/ds/<nc.example.org>/
ds update

Note: GMail has some limitations about the amount of emails that can be sent. If you have many users, it is worth to build and use your own SMTP server in order to send notifications. This article describes how to install Postfix in a container and configure it as a SMTP server:

2 Installing nextcloud in RaspberryPi

The installation steps in this case are almost the same as for the case of a VPS, but a RaspberryPi usually does not have a public IP and cannot have a domain name. So, we will have to access it with a local IP. For this reason we have to make sure that our RPi has a fixed IP (not an automatic one that can change any time).

2.1 Set a fixed IP

If out RPi is in the network 192.168.1.0/24 and we want to set a fixed IP of 192.168.1.200 to its WiFi interface, we can edit /etc/dhcpcd.conf and append these lines to it:

interface wlan0
static ip_address=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

Reboot the RPi so that this takes effect. This has been tested on raspbian/buster.

2.2 Install nextcloud

Installation steps and instructions are the same as for the VPS. However, because we don't have a domain name, we also cannot get a SSL certificate, so don't need to install wsproxy.

  • Install docker:
    curl -fsSL https://get.docker.com -o get-docker.sh
    sh get-docker.sh
    
  • Install docker-scripts:
    apt install m4 git
    git clone https://gitlab.com/docker-scripts/ds /opt/docker-scripts/ds
    cd /opt/docker-scripts/ds/
    make install
    
  • Install nextcloud:
    ds pull nextcloud
    ds init nextcloud @nextcloud
    cd /var/ds/nextcloud/
    vim settings.sh
    vim apps.txt
    ds make
    

Make sure to change at least the ADMIN_PASS on settings.sh. Also make sure to add the line PORTS"80:80 443:443"= below the DOMAIN line (this is needed because we are not using the Web Server Proxy).

I don't recommend using a MySQL server for a RPi installation of nextcloud, but it would be nice if you could set properly the settings GMAIL_ADDRESS and GMAIL_PASSWD, so that you could receive notification emails from your nextcloud (look at the end of settings.sh).

2.3 Mount an external disk drive (optional)

A RPi usually has a small disk. If we want to use nextcloud as a backup for our data (for example to store photos), we have to mount an external hard drive and configure nextcloud to use it as a data storage.

For mounting an external drive use these instructions: https://www.raspberrypi.org/documentation/configuration/external-storage.md Mount it on a directory like this: `/var/ds/nextcloud/www/data-external`, which is inside the container. Then follow these steps:

  • Make it writable by apache:
    ds exec ls -al data-external
    ds exec chown www-data: -R data-external
    ds exec ls -al data-external
    
  • Copy any existing data from the old directory to the new one:
    ds exec ls -al data/
    ds exec rsysnc -a data/ data-external/
    ds exec ls -al data-external/
    
  • Change the configuration of nextcloud to use the new data directory:
    ds occ config:system:get datadirectory
    ds occ config:system:set datadirectory --value=/var/www/html/data-external
    cat www/config/config.php | grep datadirectory
    

Date: 2019-08-18

Author: Dashamir Hoxha

Created: 2019-08-19 Mon 09:27

Emacs 25.2.2 (Org mode 8.2.10)

Validate

OpenPGP Web Key Directory

OpenPGP Web Key DirectoryOpenPGP Web Key DirectoryTable of Contents1. Introduction2. How WKD works3. Building a WKD3.1. Create the direct...… Continue reading

SMTP Server with LDAP Authentication

Published on April 17, 2021

Using WireGuard VPN

Published on November 09, 2020