This article explains how to install Nextcloud on two DreamCompute instances. One instance is for the application itself and the other instance for the database it uses.

First, create a Security Group for the database instance. This is so it allows TCP on port 3306, the MySQL/MariaDB port. View the following two articles for further instructions:

Next, launch two Ubuntu 16.04 LTS instances.

The first instance will be for the database only.

The second instance is for the webserver NextCloud will run on.

View the following category of articles for different ways to do this:

When launching the database instance, make sure to assign the Security Group you just created in Step 1 above. If you forgot to add it while creating the instance, you can still add it later.

Use a volume based instance

It is recommended to boot a volume backed instance as they are permanent as opposed to ephemeral disks and can be larger than 80GB in size if larger amounts of data will be stored. This can be done in the DreamCompute dashboard or with the OpenStack command line client.

Step 3 — Installing MariaDB on instance #1

In order to install MariaDB on your database instance, first, log into the instance with with your default username and security key: Next, switch to your root user so you can install MariaDB: [user@dbinstance]$ sudo su - [root@dbinstance]# As your root user, install mariadb by running: [root@dbinstance]# apt update [root@dbinstance]# apt install mariadb-server During installation the root database user will be set up without a password, but an authentication plugin will prevent login from anyone but the operating system root user. A password can be set if desired.

Step 4 — Configuring MariaDB

Changing the bind address Edit the 50-server.cnf file located at /etc/mysql/mariadb.conf.d/50-server.cnf. It will show the following: [user@dbinstance]$ vim /etc/mysql/mariadb.conf.d/50-server.cnf bind-address = 127.0.0.1 Edit this to change the IP to your database instance. bind-address = $IP where $IP is the IP address of the database instance. If you have private networking enabled, this will be the private IP address and not the floating IP if your database instance has one. This makes the database listen to connections from its IP address instead of only listening on 127.0.0.1 (the localhost). Allowing root login from a foreign IP address The database will now listen to connections from other instances, but you must allow users to log in from another IP address. Do this by logging into the DB as root. [root@dbinstance]# mysql -u root Then run the following commands to create a database named 'nextcloud'. MariaDB [(none)]> create database nextcloud; In the next command, change $IP to the IP address of the second instance you created for the web server. Do not add the IP address of the database instance as this will cause it to not connect. Make sure to leave the single quotes around username, IP, and password. For example, if your password is Xhd379s, enter it like this 'Xhd379s' MariaDB [(none)]> GRANT ALL ON nextcloud.* TO 'nextclouduser'@'$IP' IDENTIFIED BY '$PASSWORD'; Check to confirm the user was added: MariaDB [(none)]> select user from mysql.db where db='nextcloud'; +---------------+ | user | +---------------+ | nextclouduser | +---------------+ Flush all privileges when finished. MariaDB [(none)]> flush privileges; If you want to allow root login from any IP address, you can change $IP to '%'. However this is not recommended, especially if your database instance has a public IP address (because then anyone can try to access it). Log out of the database: MariaDB [(none)]> quit Bye Next, restart the mariadb service so the new configs are loaded by running: [root@dbinstance]# service mysql restart

This completes the installation of the database instance.

Step 5 — Installing the Nextcloud application on instance #2

Installing dependencies You must now deploy the frontend application. Log into the second instance you created. This is the instance you will install Nextcloud on. Once logged in, switch to the root shell again by running: [user@instance]$ sudo su - [root@instance]# Then run the following commands to install Nextcloud and its dependencies. [root@instance]# apt update [root@instance]# apt-get install apache2 libapache2-mod-php7.0 unzip [root@instance]# apt-get install php7.0-gd php7.0-json php7.0-mysql php7.0-curl \ php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip The backslash character \ is used when entering a long command. When you enter the \, the terminal command continues to the next line until you finish entering it. You could also remove the \ character and put every parameter into a single line. Step 6 — Downloading Nextcloud Now we need to download the actual Nextcloud application. Navigate to https://nextcloud.com/install/#instructions-server in a browser. Right click the Download Nextcloud button. From the dropdown menu click 'copy link address'. In your root shell run the following (change the version to the link you just copied). [root@instance]# wget https://download.nextcloud.com/server/releases/nextcloud-12.0.4.zip This will download a compressed copy of the Nextcloud application. Decompress the file by running the following (change the version number to the version you're using). [root@instance]# unzip nextcloud-12.0.3.zip Setting up the nextcloud directory You must now copy Nextcloud to the directory /var/www/nextcloud. Run the following: [root@instance]# cp -R nextcloud /var/www/ This creates a directory called 'nextcloud' in your current directory. Change the permissions of the nextcloud directory so the web user, www-data in this case, can access it. Run the following: [root@instance]# chown -R www-data:www-data /var/www/nextcloud

Step 7 — Configuring Apache

You must now configure Apache to use Nextcloud. Create a file in the directory /etc/apache2/sites-available called 'nextcloud.conf'. [root@instance]# touch /etc/apache2/sites-available/nextcloud.conf Add the following contents to this file: Alias /nextcloud "/var/www/nextcloud/" <Directory /var/www/nextcloud/> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /var/www/nextcloud SetEnv HTTP_HOME /var/www/nextcloud </Directory>

Next, symlink /etc/apache2/sites-enabled/nextcloud.conf to /etc/apache2/sites-available/nextcloud.conf by running the following:

[root@instance]# ln -s /etc/apache2/sites-available/nextcloud.conf \ /etc/apache2/sites-enabled/nextcloud.conf

Nextcloud also needs certain apache modules to run properly. Enable them by running:

[root@instance]# a2enmod rewrite

You should also use SSL with Nextcloud to protect login information and data. Apache installed on Ubuntu comes with a self-signed cert. To enable SSL using that certificate, run:

[root@instance]# a2enmod ssl [root@instance]# a2ensite default-ssl [root@instance]# service apache2 restart

Step 8 — Finishing the Installation