Ubuntu Server 18.04 – Setting up and configuring Nextcloud

How to use the Docker Compose command

I figured we’d end this chapter with a fun activity: setting up our very own Nextcloud server. Nextcloud is a very useful web application that’s handy for any organization. Even if you’re not working on a company network, Nextcloud is a great asset for even a single user. Personally, I use it every day and can’t imagine life without it. You can use it to synchronize files between machines, store and sync contacts, keep track of tasks you’re working on, fetch email from a mail server, and more. To complete this activity, you’ll need a web server to work with. Nextcloud supports multiple different web server platforms, but in this example, we’ll be using Apache.

You’ll also need an installation of MySQL or MariaDB, as Nextcloud will need its own database. We went over installing and managing MariaDB databases in Chapter 9, Managing Databases. I’ll give you all the commands you’ll need to set up the database in this section, but refer back to Chapter 9, Managing Databases if any of these commands confuse you.

To get started, we need to download Nextcloud. To do so, head on over to the project’s website at https://www.nextcloud.com and navigate to the Download section. The layout of this site may change from time to time, but as of the time of this writing, the download link is at the top-right corner of the page. Once there, look for a Get Nextcloud Server section, and click on the Download button right underneath that. You should see a large Download Nextcloud button here, but don’t click on it. Instead, right-click on it and click Copy link address or a similarly named option, depending on the browser you use. This should copy the link for the download to your clipboard.

Next, open an SSH session to your web server. Make sure you’re currently working from your home directory, and execute the following command:

wget <URL of Nextcloud>

To get the Nextcloud URL, simply paste the URL into your Terminal after typing wget. Your entire command will look similar to the following (the version number changes constantly as they release new versions):

wget https://download.nextcloud.com/server/releases/nextcloud-13.0.0.zip

This command will download the Nextcloud software locally to your current working directory. Next, we’ll need to unzip the archive:

unzip nextcloud-13.0.0.zip

If you get an error message insinuating that the unzip command is not available, you may need to install it:

sudo apt install unzip

Now, let’s move the newly extracted nextcloud directory to /var/www/html:

sudo mv nextcloud /var/www/html/nextcloud

In order for Nextcloud to function, the user account that Apache uses to serve content will need full access to it. Let’s use the following command to give the user www-data ownership of the nextcloud directory:

sudo chown www-data:www-data -R /var/www/html/nextcloud

Now, you should have the required files for the Nextcloud software installed on the server in the /var/www/nextcloud directory. In order for this to work, though, Apache will need a configuration file that includes /var/www/nextcloud as its Document Root. We can create the file we need at the following location:

/etc/apache2/sites-available/nextcloud.conf

Example content to include in that file is as follows:

Alias /nextcloud "/var/www/html/nextcloud/" 
 
<Directory /var/www/html/nextcloud/> 
  Options +FollowSymlinks 
  AllowOverride All 
 
 <IfModule mod_dav.c> 
  Dav off 
 </IfModule> 
 
 SetEnv HOME /var/www/html/nextcloud 
 SetEnv HTTP_HOME /var/www/html/nextcloud 
</Directory> 

Next, we enable the new site:

sudo a2ensite nextcloud.conf 

Next, we’ll need to make a change to Apache. First, we’ll need to ensure that the libapache2-mod-php7.2 package is installed since Nextcloud requires PHP, but we’ll need some additional packages as well. You can install Nextcloud’s prerequisite packages with the following command:

sudo apt install libapache2-mod-php7.2 php7.2-curl php7.2-gd php7.2-intl php7.2-mbstring php7.2-mysql php7.2-xml php7.2-zip 

Next, restart Apache so it can take advantage of the new PHP plugin:

sudo systemctl restart apache2 

At this point, we’ll need a MySQL or MariaDB database for Nextcloud to use. This database can exist on another server, or you can share it on the same server you installed Nextcloud on. If you haven’t already set up MariaDB, a walk-through was covered during Chapter 9, Managing Databases. At this point, it’s assumed that you already have MariaDB installed and running.

Log in to your MariaDB instance as your root user, or a user with full root privileges. You can create the Nextcloud database with the following command:

CREATE DATABASE nextcloud; 

Next, we’ll need to add a new user to MariaDB for Nextcloud and give that user full access to the nextcloud database. We can take care of both with the following command:

GRANT ALL ON nextcloud.* to 'nextcloud'@'localhost' IDENTIFIED BY 'super_secret_password'; 

Make sure to change super_secret_password to a very strong (preferably randomly generated) password. Make sure you save this password in a safe place.

Now we have all we need in order to configure Nextcloud. You should now be able to visit your Nextcloud instance in a web browser. Just enter a URL similar to the following, replacing the sample IP address with the one for your server:

http://192.168.1.100/nextcloud 

If you’re using a subdomain and gave Nextcloud its own virtual host, that URL would then be something like this:

http://nextcloud.yourdomain.com 

You should see a page asking you to configure Nextcloud:

Nextcloud configuration page
If you do not see this page, make sure that the /var/www/html/nextcloud directory is accessible via Apache. Also, make sure you have an appropriate virtual host for Nextcloud referencing this directory as its Document Root.

This page will ask you for several pieces of information. First, you’ll be asked for Username and Password. This is not asking you for a pre-existing account, but actually to set up a brand-new administrator account. This shouldn’t be an account you’ll use on a day-to-day basis, but instead an admin account you’ll use only when you want to add users and maintain your system. Please note that it won’t ask you to confirm the password, so you’ll want to make certain you’re entering the password you think you are. It’s perhaps safer to type the password in a text editor, and then copy and paste the password into the Password box to make sure you don’t lock yourself out.

The Data folder will default to /var/www/html/nextcloud/data. This default is normally fine, but if you have configured your server to have a separate data partition, you can configure that here. If you plan on storing a large amount of data on your Nextcloud server, setting up a separate partition for it may be a good idea. If you do, you can set that here. Otherwise, leave the default.

In the next section, you’ll be asked to fill in information for the Nextcloud database we created earlier:

Nextcloud configuration page (database section)

The Database user and Database password will use the values we created when we set up the MariaDB database for Nextcloud earlier. In my examples, I used nextcloud for the username as well as the Database name. The password will be whatever it is you used for the password when we set up the database user account and grant. Finally, the database server defaults to localhost, which is correct as long as you set up the database on the same machine as the Nextcloud server. If not, enter the server’s IP address here.

That’s it! Assuming all went well, Nextcloud will set itself up in the background and you’ll then continue to the main screen. Since you only created an admin account so far, I recommend you create an account for yourself, as well as any friends or colleagues you’d like to have check out your Nextcloud server. To do so, click on the top-right corner of the Nextcloud page, where it shows the username you’re logged in with. When you click on this, you’ll see an option for Users. On the Users screen, you’ll be able to add additional users to access Nextcloud. Simply fill out the Username and Password fields at the top of the screen, and click on Create.

As an administrative user, you can enable or disable various apps that are used by your users. Out of the box, Nextcloud has a basic suite of Apps enabled, such as the Files and Gallery plugins. There are many more apps that you can enable in order to extend its functionality. On the top-right corner of the main screen of Nextcloud you’ll find an icon that looks like a gear, and if you click on it, you will find a link to Apps which will allow you to add additional functionality. Feel free to enable additional apps to extend Nextcloud’s capabilities. Some of my must-haves include Calendar and Contacts, Tasks.

Now, you have your very own Nextcloud server. I find Nextcloud to be a very useful platform, something I’ve come to depend on for my calendar, contacts, and more. Some Linux desktop environments (such as GNOME) allow you to add your Nextcloud account right to your desktop, which will allow calendar and contact syncing with your desktop or laptop. I’m sure you’ll agree that Nextcloud is a very useful asset to have available. For more information on using Nextcloud, check out the manual. In fact, it’s available in the files app from within the application itself.

Comments are closed.