Setting up NextCloud

· Allanderek's blog

#programming

Mostly notes for myself on how I setup nextcloud on Time4VPS. I was mostly following this article but found it was slightly wrong in a couple of places and missed out the odd thing.

# Install the dependencies

1sudo apt install apache2 mariadb-server libapache2-mod-php unzip
2
3sudo apt install php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip

# Download nextcloud

Navigate here to find out the latest verison. Then (substituting in the latest version for 21.0.0):

1cd /var/www
2sudo wget https://download.nextcloud.com/server/releases/nextcloud-21.0.0.zip
3sudo unzip nextcloud-21.0.0.zip

# Prepare the database

1sudo mysql
1CREATE USER 'nextcloud' IDENTIFIED BY 'nextcloud';
2CREATE DATABASE nextcloud;
3GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@localhost IDENTIFIED BY nextcloud; and then flush'em FLUSH PRIVILEGES;
4quit;

The IDENTIFIED BY 'nextcloud' part is basically setting the password, which you will need later.

# Configuring Apache

This is just giving permissions to the user 'nextcloud' which our apache

1cd /var/www
2sudo chmod 750 nextcloud -R
3sudo chown www-data:www-data nextcloud -R

# Configure next cloud

Use whatever editor you like, let's pretent it is nvim:

1cd /etc/apache2/sites-available/
2nvim nextcloud.conf

Here is the one I used, but obviously you'll need to substitute in your own host:

 1Alias /nextcloud "/var/www/nextcloud/"
 2
 3<Directory /var/www/nextcloud/>
 4        Require all granted
 5        AllowOverride All
 6        Options FollowSymLinks MultiViews
 7
 8        <IfModule mod_dav.c>
 9                Dav off
10        </IfModule>
11
12</Directory>
13<IfModule mod_ssl.c>
14
15    <VirtualHost nextcloud.poleprediction.com:443>
16
17        ServerAdmin my_email.com
18        ServerName nextcloud.poleprediction.com
19
20        DocumentRoot /var/www/nextcloud
21
22        ErrorLog ${APACHE_LOG_DIR}/error.log
23        CustomLog ${APACHE_LOG_DIR}/access.log combined
24
25        SSLEngine on
26        SSLCertificateFile      /etc/ssl/certs/poleprediction.com.pem
27        SSLCertificateKeyFile   /etc/ssl/private/poleprediction.com.key.pem
28
29        <FilesMatch "\.(cgi|shtml|phtml|php)$">
30            SSLOptions +StdEnvVars
31        </FilesMatch>
32        <Directory /usr/lib/cgi-bin>
33            SSLOptions +StdEnvVars
34        </Directory>
35    </VirtualHost>
36</IfModule>

# Finally enable nextcloud

Well enable nextcloud and restart apache:

1sudo a2ensite nextcloud
2sudo a2enmod rewrite headers env dir mime
3sudo systemctl restart apache2

You should be able to now visit the root domain and setup nextcloud via its web interface.

# Cron

I am using the nexcloud rss app, so I needed to setup cron mode.

1crontab -u www-data -e

Add the following simple line which will mean the cron job is run every 5 minutes:

*/5  *  *  *  * php -f /var/www/nextcloud/cron.php

# SSL

I'm not sure I understand everything here, but this was the guide I found most useful.

I just installed the certbot using apt-get

1apt-get install certbot python3-certbot-apache

Then I basically just ran the certbot and it mostly does everything for us:

1certbot --apache --agree-tos --rsa-key-size 4096 --email allan@poleprediction.com --redirect -d nextcloud.poleprediction.com

Finally once that has done its business it's worth adding to the configuration (/etc/apache2/sites-available/nextcloud.conf:

        <VirtualHost *:80>
           ServerName cloud.nextcloud.com
           Redirect permanent / https://cloud.nextcloud.com/
        </VirtualHost>

This just redirects all incoming http traffic to https.