How to Build Your Own Cloud File Sync with Nextcloud

Nextcloud

Services like Dropbox allow you to easily access your files on multiple devices. However, you may want more control over them. In less than 30 minutes, you can have your own cloud synchronization service on a server that you control via Nextcloud.

What is Nextcloud?

Nextcloud is open source software that lets you synchronize files between your PC and other devices, just like you would with Dropbox, Onedrive or Google Drive. In addition, Nextcloud has a dynamic application ecosystem that allows you to do more than just synchronize files. You can use Nextcloud for calendar and contact management or to run a web-based IMAP email client. You can even set up a live chat program exclusively for yourself and anyone else who can access your server.

Before going into details, however, there is a warning. Once you start using Nextcloud, it’s up to you to maintain the server. This means that in addition to managing Nextcloud software, you must ensure that the operating system of the underlying server remains up to date with the patches. Nextcloud servers are generally problem-free, but if something isn’t right, it’s up to you to fix it.

The good news is that there are loads of blogs, forums, and help pages to help you with troubleshooting. If you have a problem, it probably happened to someone else and there is a solution.

What you will need

The Nextcloud interface.The default Nextcloud web interface.

You will need the following three items to get started with Nextcloud:

A virtual server running Ubuntu 18.04
The Bash shell on your computer desktop.
A domain name.

For our examples, we will create several usernames and passwords, including the following:

Your server username and root password.
A standard server username and password with administrative privileges.
Nextcloud username and password.

For the purposes of this tutorial, we are using a virtual server running Ubuntu 18.04 from DigitalOcean. You can, however, use any provider you like, including Linode or AWS. Whichever service you choose, the key is to run Ubuntu 18.04 (the long-term support version current at the time of this writing) to avoid any potential problems.

Each virtual server provider is a little different, but they all aim to set up an operational server with a few clicks of the mouse. To get started, we recommend that you use a base level server on a trial basis until you get used to Nextcloud. Digital Ocean’s The $ 5 droplet offers 1 GB of RAM, 1 processor core, 1 TB of data transfer and 25 GB of storage. Linode offers a similar VPS for the same price.

Unless you are comfortable with SSH keys, ask your provider for password-based root credentials to get started. Once your server is running and you are comfortable with the command line, you can consult your provider’s help pages for how to add SSH keys for a more secure connection.

If your computer is running Windows 10, you will need to install the Windows subsystem for Linux and get a Bash shell with Linux utilities Continue. If you are using Linux or macOS, the Terminal program is all you need. Most Bash terminals come with SSH installed, but if not, just type sudo apt-get install ssh in the terminal window to install it.

When you buy a domain name, it doesn’t have to be a .COM address. Only you, your close friends and family will use it. For example, we have found a .XYZ domain name for only $ 1 per year which will work very well.

RELATED: The best places to buy a domain name

Prepare your server

A man standing in a data center.Gorodenkoff / Shutterstock

To prepare your server for action, you must configure a normal user account with administrative privileges. It is a very bad idea to log in as an almighty root user after the initial setup.

By now, you should have an IP address and root password from your server provider. The IP address is how you connect to the server, and the password allows you to enter.

To start, type the following (replace the Xs with the IP address of your server), then press Enter:

ssh root@XXX.XX.XX.XXX

Our IP address is 165.22.81.172, so we entered it in our order. If everything goes as planned, the remote server (where you will place Nextcloud) will ask you for a password. Type the password that your server provider gave you.

You will then be prompted to set a new password for root. Choose what you want, don’t forget it and don’t forget!

You are now inside your remote server and it is time to get to work. Press Enter after each command of this article to execute it.

First, we type the following to add a new user to the server:

adduser ian

Replace “ian” with the username you want to use. After you run this command, you are prompted to give the new user a password. After that, the rest of the information requested by the server is optional; if you don’t want to provide it, keep pressing Enter.

Then we type the following to give our new users administrative privileges:

usermod -aG sudo ian

Again, replace “ian” with the username you chose previously.

Now we open a second terminal window and type the following to make sure the new user accounts work:

ssh ian@165.22.81.172

Again, replace the above with your username and the IP address of your server. Type the password that you created for this user account when prompted. If it works, go back to the terminal window where you are logged in as root.

Now we type the following to make sure that the Ubuntu firewall works correctly:

ufw authorizes OpenSSH
ufw enable
ufw status

This last status command should return something like the image below, confirming that the firewall will not block SSH.

You will not see the part “80, 443 / tcp” yet, but we will come back to this later. Now close the root window and return to the second terminal window with the normal user.

Install Nextcloud

There was a time when you had to configure and install Nextcloud software, PHP, web server software and database all separately.

It’s much easier to use the official Snap package, which takes care of everything with a single command. There is no problem with the database or you should worry if Apache or Nginx is serving your site.

If you want to see exactly what the Snap package installs (spoiler: this is the rest of the LAMP battery, plus Redis), see the Snap Nextcloud repository on GitHub.

We type the following:

sudo snap install nextcloud

The “sudo” at the start elevates the regular user account so that it has temporary administrative rights. You will be asked for your password to perform this operation. If all goes well, in a minute or two, Nextcloud will be installed and (almost) ready for action.

Then we type the following to create a new Nextcloud user account that can log into our site:

sudo nextcloud.manual-install ianpaul correctHorseBatteryStaple

Instead of “ianpaul”, enter the username you want to use to log in to Nextcloud. The bit “correctHorseBatteryStaple” is our password. Do not use it, it comes from a very well known site XKCD comic and is just an example.

Manage domains

To make your life easier, we don’t want to use an IP address all the time to access our server. Instead, we will use a domain name that you will get again for as little as $ 1 per year. For our example, we use HowToGeekTest.xyz.

Once you have a domain, you need to manage the DNS settings of your domain registrar (where you purchased the domain) and direct them to your server provider. If you chose DigitalOcean, for example, these parameters would be ns1.digitalocean.com, ns2.digitalocean.com and ns3.digitalocean.com.

Then go to your server provider (for example, DigitalOcean, Linode or whatever you have chosen) and add the new domain to your account. You’ll need to add an A record that points to your IP address, a CNAME record if you don’t want to use “www” all the time, and NS records if they weren’t added automatically.

The image below shows an example of DigitalOcean.

A grid of DigitalOcean DNS records.

Technically, it can take up to 24 hours before your domain is available, but it usually starts working in a few minutes.

Return to Nextcloud

With the domain configured, we can go back to the end of Nextcloud in the terminal. If you have disconnected from the server with your normal user account (ian@165.22.81.172 in our example), reconnect.

Now we type the following to add our new domain to Nextcloud:

config sudo nextcloud.occ: system: set trusted_domains 1 –value = howtogeektest.xyz

After “–value =”, enter your domain rather than ours (howtogeektest.xyz).

Then we type the following to make sure our new domain has been added correctly:

config sudo nextcloud.occ: system: get trusted_domains

The terminal should print something like the image below.

Then we type the following to make sure we can use the ports we want by letting them go through the firewall:

sudo ufw allows 80,443 / tcp

Port 80 is used for unencrypted HTTP traffic, while 443 is for SSL / TLS.

Speaking of which, we’re going to need a free SSL / TLS certificate from Let’s Encrypt, so we type the following:

sudo nextcloud.enable-https allows to encrypt

Once the Let’s Encrypt generator starts, it requests an email address and your Nextcloud domain name. Just follow the instructions and you should have a secure website certificate in no time. If Let’s Encrypt worked, it’s time to test your configuration.

Access your new domain (like our howtogeektest.xyz). You should see a Nextcloud login page (see below) with a lock icon in the address bar.

Nextcloud login page.

If you see the login page, you’re ready to go. Otherwise, wait a few hours and try again. If you want to troubleshoot immediately, you can see if the server responds via the IP address.

For this to work, we need to type the following, to add the IP address to our trusted domains:

config sudo nextcloud.occ: system: set trusted_domains 2 –value = 165.22.81.172

Note that we used “trusted_domains 2” and not “trusted_domains 1.” If you just repeat “trusted_domains 1”, you will overwrite your real domain name in the list of trusted domains and will not be able to use it.

Once done, enter the IP address in your browser’s address bar and you should see the login page above. Otherwise, there was a problem with the installation.

Since we do not have an SSL certificate for the IP address, it will not be able to connect securely. For this reason, we suggest that you remove the IP from the list of trusted domains after confirming that the server is working. To do this, type the following:

config sudo nextcloud.occ: system: delete secure_domains 2

Increase performance

If your Nextcloud server is not functioning well, you may need to increase the memory limit. By default, it is 128 MB. To increase this number to 512 MB, you must connect to the server using the terminal and enter the following:

sudo snap set nextcloud php.memory-limit = 512M.

Now that Nextcloud is operational, you can connect, browse available apps, share files with others, and install Nextcloud on your desktop and mobile devices for multi-device synchronization. Nextcloud offers desktop synchronization tools and mobile apps for Windows, Mac, Linux, iPhone, iPad and Android.

Welcome to your own personal drop box!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.