Build Your Own Private Cloud with NextCloud

3 minute read

After trying many note taking apps I decide to use Joplin which is an open source project, there are many options out there for synchronizing the notes via OneDrive, Dropbox etc, I want take full control of my data, so I tend to NextCloud, which is also supported by Joplin, this post describes how to install Nextcloud on a VPS.

Prerequisite

I will be using Droplet provided by Digital Ocean with Ubuntu 20.04 installed, first we need to create droplet, this can be done via web interface, Digital Ocean also provides a command line tool called doctl and provides very detailed reference manual.

To create a droplet instance, we need the following info:

First of all we need to install doctl and configure it:

$ brew install doctl
$ sudo snap install doctl

Configuring doctl need a access token with can be obtained from Applications & API page in the control panel, please note that, the token string will be displayed only once.

$ doctl auth init  # When prompt, paste the token get from above

List data center locations

 doctl compute region list
 Slug    Name               Available
 nyc1    New York 1         true
 sfo1    San Francisco 1    false
 nyc2    New York 2         false
 ams2    Amsterdam 2        false
 sgp1    Singapore 1        true
 lon1    London 1           true
 nyc3    New York 3         true
 ams3    Amsterdam 3        true
 fra1    Frankfurt 1        true
 tor1    Toronto 1          true
 sfo2    San Francisco 2    false
 blr1    Bangalore 1        true
 sfo3    San Francisco 3    true

List distribution image

$ doctl compute image list-distribution --public
[...]
93525508    20.04 (LTS) x64       snapshot    Ubuntu          ubuntu-20-04-x64       true      15

Get SSH Key

$ doctl compute ssh-key list
ID          Name                   FingerPrint
21071951    fudongbai@gmail.com    11:31:65:89:15:12:b8:cc:88:b8:73:32:81:6d:25:7a

List plans

$ doctl compute size list
Slug                 Memory    VCPUs    Disk    Price Monthly    Price Hourly
s-1vcpu-1gb          1024      1        25      5.00             0.007440
s-1vcpu-1gb-amd      1024      1        25      6.00             0.008930
[...]

Create droplet

Now we have all the required information for creating a droplet, do as follows:

 $ doctl compute droplet create --region tor1 --image ubuntu-20-04-x64 --size s-1vcpu-1gb --ssh-keys 11:31:65:89:15:12:b8:cc:88:b8:73:32:81:6d:25:7a vps

 ID           Name         Public IPv4    Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                     VPC UUID    Status    Tags    Features         Volumes
 269425708    NextCloud                                                  1024      1        25      tor1      Ubuntu 20.04 (LTS) x64                new               droplet_agent

doctl can list all the created droplets, which contain the IP address that we need to do ssh login:

$ doctl compute droplet list
 ID           Name         Public IPv4      Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                     VPC UUID                                Status    Tags    Features                            Volumes
 269425708    NextCloud    167.99.191.22    10.118.0.2                     1024      1        25      tor1      Ubuntu 20.04 (LTS) x64    e8a7e71a-d0d7-4e8b-81ca-4a3627e0c5ba    new               droplet_agent,private_networking

Remove droplet

$ doctl compute droplet delete <DROPLET-ID>

Next create a user account and add to sudo group:

$ username=fudongbai
$ password=mypassword
$ adduser --disabled-password --gecos "" $username
$ echo "$username:$password" | chpasswd
$ usermod -aG sudo $username

Install NextCloud

NextCloud can be installed with snap:

$ sudo snap install nextcloud

$ username=admin
$ password=admin
$ sudo nextcloud.manual-install $username $password
Nextcloud was successfully installed

$ sudo nextcloud.occ config:system:get trusted_domains
localhost

$ ipaddr=$(ifconfig eth0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
$ sudo nextcloud.occ config:system:set trusted_domains 1 --value=$ipaddr
System config value trusted_domains => 1 set to string 178.128.232.161

$ sudo nextcloud.occ config:system:get trusted_domains
localhost
178.128.232.161

$ sudo nextcloud.enable-https self-signed
Generating key and self-signed certificate... done
Restarting apache... done

Now go to https://178.128.232.161 to manage your files, or download clients for your computer, mobile phones are also supported, get it from F-Droid for Android, or App Store for iOS.

NextCloud will use port 80 by default, if the port is already used, change it to another one:

$ sudo snap set nextcloud ports.http=81

Install Apps

There are many apps out there to extend the function of NextCoud, here is a list of apps I used:

$ sudo nextcloud.occ app:install spreed
$ sudo nextcloud.occ app:install maps
$ sudo nextcloud.occ app:install calendar
$ sudo nextcloud.occ app:install deck
$ sudo nextcloud.occ app:install notes
$ sudo nextcloud.occ app:install tasks
$ sudo nextcloud.occ app:install contacts

References

Updated: