Your private "cloud" with Nextcloud
If you find this post helpful consider sending Jaime some sats: https://tippin.me/@j4imefoo
Today we all have a mobile phone in our pocket. This phone is synchronized with the so-called “cloud” thanks to which your data is conveniently shared with all the devices connected to the same account. This gives us a lot of comfort by being able to see each change reflected on all our screens at the same time and being able to access our data from anywhere.
But unfortunately, we know that this "cloud" is nothing more than "someone else's computer".
Why should we entrust our calendars, contacts, photos and personal documents to someone who is not ourselves, who does not even have our interests in mind and for whom we are even one more product? You're right, we shouldn't.
What would you think if I told you that there is a solution today that allows us to manage our personal information in the same way that we would through the "cloud"?
We are very lucky to have a product that has all the features we need, with a long track record and is also free and open source software. I present to you Nextcloud.
What do we need
Being all the software that we will use free, we will focus first on the hardware.
Where do you want to install it? What use will you give? How many users? What response time do you need? How much fault tolerance for availability? These will be some of the questions you should ask yourself before deciding where you are going to install your Nextcloud instance. Here are some examples to help guide you in your decision:
- I'm interested in an installation to tinker with. I don't want to dedicate more hardware than a raspberry that I have at home. I will use Nextcloud to share important documents and photos with the family, inside the house.
- I want to use it continuously with my family, friends, or employees of my small business. We will have shared calendars and contacts synced continuously. We will make use of the sharing of files, photos and even collaborate online in the creation of documents.
If you already know which of the situations you identify with, you already know more or less what to expect in terms of hardware.
In the case of having it at home we will use a Raspberry PI or computer that we can leave on and in case we want to have it away from home for reasons of connectivity or resources, we can use any of the hosting services that exist on the market. I might recommend host4coins, Digital Ocean or Linode.
Nextcloud does not require a lot of resources, but at least 1GB of RAM would be recommended. Since one of its uses will be to store files and photos, we will also need some hard drive capacity.
If we are going to use it and it is not just about tinkering, it would also be convenient to register a domain name that points to our IP. In the case of wanting to install it at home without having a fixed IP, there are a wide variety of companies on the Internet that offer dynamic DNS. In our case, we select jaimescloud.xyz
To start, we will connect to our server by ssh:
Nextcloud is a web application written in PHP. We will therefore need a web server and a database.
The official installation involves installing the well-known Apache web server. However, as it is an installation that we may have to use on machines with few resources, I have opted to adapt it for nginx, which is a much lighter server.
We will use configurations created by the Nextcloud community, adapted to the official Apache ones. I have taken the liberty of adapting these configurations in turn to simplify and update them to the current versions of the different software packages that we will be using.
For the database I will opt for MariaDB.
With the software already chosen, we proceed to the installation of the different requirements.
We update our system first. We will assume that we are working with Ubuntu 20.04 LTS:
sudo apt update sudo apt upgrade
We install the necessary web server, database and php packages:
sudo apt install nginx mariadb-server sudo apt install php7.4-gd php7.4-mysql php7.4-curl php7.4-mbstring php7.4-intl php7.4-gmp php7.4-bcmath php-imagick php7.4-xml php7.4-zip php7.4-bz2 php7.4-fpm
We connect to mysql/MariaDB and create our database that will house the information of our Nextcloud installation, replacing username and password with the credentials that we choose. We write down the username and password that we will need later:
sudo mysql -uroot -p CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; GRANT ALL PRIVILEGES ON nextcloud.* TO 'username'@'localhost'; FLUSH PRIVILEGES; quit;
Download and install Nextcloud
We download Nextcloud from its page:
Download for server ->
Download Nextcloud ->
Details and download options
We go to our terminal and download it, along with the sha256 and asc file for verification, replacing x.y.z with the current version:
wget https://download.nextcloud.com/server/releases/nextcloud-x.y.z.tar.bz2 wget https://download.nextcloud.com/server/releases/nextcloud-x.y.z.tar.bz2.sha256 wget https://download.nextcloud.com/server/releases/nextcloud-x.y.z.tar.bz2.asc wget https://nextcloud.com/nextcloud.asc
We check the package:
gpg --import nextcloud.asc gpg --recv-keys 28806A878AE423A28372792ED75899B9A724937A gpg --verify nextcloud-x.y.z.tar.bz2.asc nextcloud-x.y.z.tar.bz2 sha256sum -c nextcloud-x.y.z.tar.bz2.sha256 < nextcloud-x.y.z.tar.bz2 > OK
Once verified, we extract it and copy it to the folder where it will reside from now on:
tar -xjvf nextcloud-x.y.z.tar.bz2 cp -r nextcloud /var/www
We make nginx the owner of the newly created directory:
sudo chown -R www-data:www-data /var/www/nextcloud
We need to create the main configuration file. This is the list of instructions that we give to nginx so that it knows how to behave when running our Nextcloud instance.
So we create the file
/etc/nginx/sites-available/nextcloud.conf which will contain the following lines:
We activate it by creating a link in the directory
sudo ln -s /etc/nginx/sites-available/nextcloud.conf /etc/nginx/sites-enabled/
Next we will modify a couple of PHP configurations so that Nextcloud behaves correctly and has enough memory to be able to deal with synchronizing larger files.
In the File
/etc/php/7.4/fpm/pool.d/www.conf edit the lines:
env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
We change two variables in the file
# Default is 128M memory_limit = 512M # Default is 2M upload_max_filesize = 100M
We restart php and nginx:
sudo systemctl reload php7.4-fpm.service sudo systemctl restart nginx
Secure SSL connection: letsencrypt!
If we are going to use this installation in a more "official" way, it is advisable to connect to it using SSL. For this we will need to generate our certificates. We will use certbot for this purpose:
sudo apt-get install python3-certbot-nginx sudo certbot --nginx
We will answer certbot questions. We will choose "redirect to SSL" to force the user to connect securely.
We restart nginx again to load the modified configuration file, with the directives to connect by SSL.
sudo systemctl restart nginx
We connect for the first time with our installation. In our case, https://jaimescloud.xyz.
Being the first time, it will ask us to create username and password and other data such as our database and your access password.
As soon as everything has been configured, it automatically takes us to our dashboard
In the upper right corner, if we click on our user, we can create more users and install applications
These are just some of the recommended apps. I invite the reader to discover more of so many jewels included in the huge directory:
- Contacts. Contact directory that allows access to phones and email programs through CardDAV
- Calendar. Same idea but for calendars. It will allow us to connect through CalDAV
- Photos. Storage, categorization and viewing of photos and videos in the style of Google Photos. The different programs and apps will allow us to synchronize them on the devices we want
- Files. The same idea but for files of all kinds.
- News – RSS feed manager. We can create custom RSS feeds so that the status of the articles we read is synchronized on all our devices
- Bookmarks. The same, but for the favorite links of all our browsers
- PhoneTrack. What if you wanted your family to be able to track you privately without sharing your location with "the cloud"? This AddOn makes it possible if paired with mobile Apps created for this purpose.
- Notes. Our notepad on the server, synchronized with the different apps.
As we said, there are many more that you can discover by browsing these lists. I leave as an exercise to the reader to install and test some more applications.
Sync to phone and computer: Nextcloud and DAVx5 apps
All these functionalities already described, would not be of much use if they remained only on our server. The interesting thing is the synchronization and possibility of collaboration between teams that this system offers.
On this page we can download the Nextcloud application for any of our platforms, whether computer or mobile phone.
If we also install DAVx5 on Android, we can synchronize both contacts and calendars with our new Nextcloud installation.
Much of the configuration files have been taken from the excellent documentation pages of the Nextcloud project, ordered, simplified and organized as I saw fit, trying to make the process less dry to the reader.