Setting up a Nextcloud Instance

What is Nextcloud?

Nextcloud is a free and open source solution for cloud storage. However it can also do other things, such as manage your email, notes, calender, tasks, and can even connect to the Fediverse (think Mastodon and Pleroma). Pretty much every service that Google has to offer has a much better alternative as a Nextcloud app and this is a must-have for anyone wanting to get away from Google services but still wants a traditional cloud experience (in the likes of Google Services, anyways).

Instructions

First, we need to obtain a shell prompt by ssh-ing (remote machines or local machines) or just logging in (local machines). A traditional ssh might look like this if the domain you wished to ssh into is landchad.net:

ssh root@landchad.net

We should upgrade the system and then install packages that we might need. Run the following command:

apt-get full-upgrade -y && sudo apt-get install mariadb-server php-mysql php php-gd php-mbstring php-dom php-curl php-zip php-simplexml php-xml -y

Next, we need to set up our SQL database by running a Secure Installation and creating the tables that will store data that Nextcloud will need. Run the following command:

mysql_secure_installation

When it asks for root a password, say yes and input a new and secure password. The root password here is just for the SQL database, not for the GNU/Linux system.

Answer the rest of the questions as follows:

Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
        

Next, sign into the SQL database with the new and secure password you chose before. Run the following command:

mysql -u root -p

We need to create a database for Nextcloud. Follow the instructions below and change some of the placeholders as you wish:

CREATE DATABASE nextcloud;
GRANT ALL ON nextcloud.* TO 'username'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;

Start and enable the php-fpm and the mariadb services:

systemctl enable php-fpm
systemctl start php-fpm
systemctl enable mariadb
systemctl start mariadb

Next, we need to download the latest release tarball of Nextcloud. Go to https://nextcloud.com/install/#instructions-server and copy the URL of the the .tar.bz2 tarball from the More Downloads dropdown menu then go to your server's shell prompt and download the tarball with wget. Here is an example:

wget https://download.nextcloud.com/server/releases/nextcloud-21.0.2.tar.bz2

If you already have your LandChad property set up (your web site) we can simply extract the tarball there so we don't have to do any messing around with Nginx at the moment. You may wish to have a subdomain instead, but that is out of the scope of this tutorial. Run the following command:

tar -xjf nextcloud*.tar.bz2 -C /var/www/yourwebsitedirectory

If you have multiple Nextcloud tarballs in the current working directory you might want to manually specify which one you wish to extract.

Let's correct the ownership and permissions of those files. Run the following commands after you fill in the placeholders:

chown -R www-data:www-data /var/www/yourwebsitedirectory/nextcloud
chmod -R 755 /var/www/yourwebsitedirectory/nextcloud
        

Now we need to head to Nextcloud's web interface. Go to your web browser and go to your website, but go to the subdirectory "nextcloud" instead. For example, if your domain is landchad.net and you have set up HTTPS then go to https://landchad.net/nextcloud. This will launch the configuration wizard.

Congratulations, you have set up your own Nextcloud instance.

What's Next?

Now you may be wondering: What do I do now? Here are some suggestions:

Enjoy your cloud services in freedom.


Written by Matthew "Madness" Evan