Setting up your own nextcloud server

Bharat Kalluri / 2020-12-29

I've been trying to get rid of all the dependencies which I have on google for a while. Tried nextcloud a while back but did not stick to it (for some reason, I don't seem to recollect). After lurking and listening to some conversations over at the foss united telegram group, I thought I would give nextcloud another shot.

I have completely migrated away from google drive and photos as of now and am in the process of migrating my personal calender and contacts. So far it has been a good experience. This is just a brain dump of all the steps to setup nextcloud. There is more work todo for later, but this is a good starting point.

Personally I wanted a iCloud kind of a service rather than a GSuite kind of a service. On the face of it, nextcloud seems to do a lot more things. And in the process a lot of the pieces do not seem very polished. I will be writing a more detailed review on what I liked and disliked about nextcloud sometime later.

Disclaimer, A lot of companies offer nextcloud as a service. If nextcloud is the only service you want to be hosting and you are okay with the idea of hosted services, that should be what you should be looking at. I use Hetzner as my cloud provider, looks like Hetzner provides nextcloud as a service. For 100GB they charge 3.36 € (around 300 rupees).

The domain, DNS setup, getting the instance and the total yearly cost

I bought my domain from Namecheap, I pay ₹653 for the domain per year. The blog you are looking at is hosted on Vercel. So all the DNS is managed out of Vercel as of now. I bought the server from Hetzner, the server costs around 2.89 € which is around ₹259 per month. The system has a 1 vCPU, 2GB RAM, 20GB disk space and 20TB traffic transfer. So the instance costs around ₹3120 per year. After the instance is up, the DNS of the domain needs to point to the public IP of of your instance. I am pointing the subdomain (cloud.bharatkalluri.com) to the IP of the instance.

Summing it all up, it costs me around ₹3773(3120 + 653 = 3773) per year if I self host nextcloud + blog.

System setup and installing nextcloud

Hetzner drops us into the root user by default. So let us create a user. As usual, replace whatever is in the pointy brackets with your details.

# Creating a user and making the user an admin
sudo useradd -m <username>
sudo usermod -aG sudo <username>
# Setting a password for <username>
sudo passwd <username>

Also, set a password for root.

sudo passwd root

Log out of the SSH session, log in back with the ssh <username>@<instance IP>. For some reason, Hetzner instances start with an sh shell. So, I am going to install my preferred shell, zsh.

# Installing some prerequisites for oh my zsh
sudo apt update -y && sudo apt upgrade -y
sudo apt install git zsh -y
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Now, setting up a basic firewall using ufw.

# Setup basic firewall rules
sudo ufw allow OpenSSH
sudo ufw allow https
sudo ufw allow http
sudo ufw enable

Installing nextcloud. If the instance is running ubuntu, snapd will already be pre installed. If you are running any other operating system, find the instructions to install snapd here.

# Install nextcloud
sudo snap install nextcloud
sudo nextcloud.manual-install <username> <password>
sudo nextcloud.occ config:system:set trusted_domains 1 --value=<your-domain.name>
sudo nextcloud.enable-https lets-encrypt

nextcloud generates a letsencrypt certificate for your domain and sets it up for https. Now you should be able to hit <your-domain-name> and see nextcloud running.

What next

  • Reverse proxy-ing: Currently there is no proxy sitting in front of nextcloud, so the instance is pretty much reserved for nextcloud. I will be wanting to host more services in the future. I should setup a reverse proxy (like HAProxy/Nginx).
  • Backups: Currently there is absoluetly no backups setup. I will be setting up instance level snapshots and linux backups sometime soon.
Spotify album cover

NowReading logDashboardUses