Installing Nextcloud in Ubuntu

Or, using snaps to dump large amounts of files at once, easily.

Over the past few months I’ve convinced myself that I’m in need of a shared storage solution for the house, and sometimes, the most useful of these, sftp and samba, can be cumbersome to get going on the first go-around for someone unfamiliar with the tools or for someone that’s only on a phone. Those tools can also be a real pain to set back up when something goes wrong. Now, I don’t necessarily say that Nextcloud itself is better at this than any other solution, but because it’s web-based, it’s cross-platform. It also has apps for Android and iOS. If you can run a modern browser, you can run Nextcloud, which means others that I setup on the system have an easy way to get connected. Then, there are always the desktop apps which make syncing important folders a no-brainer.

Digging deep into Nextcloud and the various ways of implementing it gave me a good view of the pros and cons of each. Manual install (Apache or nginx, MySQL or MariaDB, PHP, Nextcloud) was cumbersome and fairly difficult to install, connect and maintain. It’s obviously officially supported and one of the best ways to install if you have distributed resources. I didn’t write it off, since this blog is installed that way, but I wanted to also explore the other options available to me. The docker image was very appealing. It is well documented and official (from Docker). It has all the features of the manually installed Nextcloud as far as I could see, but requires the separate installation and maintenance of a PPA and Docker itself. And then, there’s the snapd version. Snap is the official containerization software from Canonical and Nextcloud themselves publish a snap. When I realized that both of the solutions were first-party published and supported, this incentivized me to dive in and at least check it out.

So, here I am. Installing the Nextcloud snap on Ubuntu 18.04 Server Edition. No special tooling required, just one single command.

$ sudo snap install nextcloud

I thought to myself that it couldn’t be that easy, but yep. It is. Nextcloud is installed and ready to go if you’re ok with the defaults. The README.md file found on Nextcloud’s snap github page is resource rich and helped me get the basics of how the snap worked down. Below is basically the way I’ve got it set up minus all the mistakes.

Create an Admin Account and Automate the Initial Config

$ sudo nextcloud.manual-install leo password

Here, leo is my desired admin username and password is a temporary password. For initial setup it is literally “password.” I try to keep the password simple and change it once I’m fully logged into Nextcloud. This prevents typing out passwords in plaintext and storing it in the terminal history.

Accessing the WebUI with Names and IPs

By default, Nextcloud only “trusts” the internal URL of localhost. Accessing it any other way would give an error and prevent login. Since I was installing this on a headless server, this isn’t useful to me at all outside of rudimentary testing, but I can understand the security reasoning. To add domains to the list I needed to interact with the nextcloud.occ so I could add my name and IP address.

$ sudo nextcloud.occ config:system:set trusted_domains 1 --value=domainname

For my first name, I set trusted_domains to 1 and added domainname above. My name was actually different, but for demonstration purposes that’s what I’ll use here.

Let’s say we wanted to access via IP address, too. If you’re accessing over a VPN without having internal DNS configured or just plain prefer IP’s to anything else, this will be relevant. I like having the backup of plain IP address, so adding was done simply by incrementing the trusted_domains option by 1 for my additional IP.

$ sudo nextcloud.occ config:system:set trusted_domains 2 --value=192.168.1.10

You can check on your configured domains with one more command.

$ sudo nextcloud.occ config:system:get trusted_domains

Encrypting the Traffic There and Back

By default, the Nextcloud snap will use HTTP, which is fine for some internal-only configurations, but I’m a little more paranoid than that. I wanted encryption, so I used nextcloud.enable-https to generate a self-signed cert just for that purpose. If I were setting this up for the web and wanted an appropriate Let’s Encrypt cert, I would swap self-signed for lets-encrypt in the next command. Done and done.

$ sudo nextcloud.enable-https self-signed 

Moving Data From the Default Location

Maybe you want your data to live in /var/snap/nextcloud/current/nextcloud/data. Who am I to tell you to move it?

This is probably the most complicated bit of the setup, and isn’t strictly necessary in all cases. For me, since I’m storing all of my user data on an external USB drive, it was. It is absolutely required that you mount your storage in /media, or the snap confinement will prevent the data from being read.

To make this work, I connected the removable-media plug as mentioned in the README in order to grant the snap permission to access external drives.

$ sudo snap connect nextcloud:removable-media

Prior to this, I mounted my external drive at /media/nextcloud/ . Then, created a data directory inside. The next thing I did was update the Nextcloud configuration file to point to my newly created directory by editing /var/snap/nextcloud/current/nextcloud/config/config.php and making sure the datadirectory setting is pointing to the right place.

I started with editing the configuration file

$ sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php

And, once in, changed the line below

'datadirectory' => '/media/nextcloud/data',

Once done, I saved the file and stopped the snap from running for a moment:

$ sudo snap disable nextcloud 

Moved the default data directory to the new place in /media:

$ sudo mv /var/snap/nextcloud/common/nextcloud/data /media/nextcloud/data

And, finally, re-enabled the snap

$ sudo snap enable nextcloud 

That’s it! I logged in, changed passwords, added plugins, users, and configured things the way I liked. The auto-backup of photos from phones is probably my favorite feature now! Any time I’m on wifi, my photos get sucked up by Nextcloud for safe keeping.

3 thoughts on “Installing Nextcloud in Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *