Setting up NextCloud

· Allanderek's blog


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
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
3sudo unzip

Prepare the database #

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

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/"
 3<Directory /var/www/nextcloud/>
 4        Require all granted
 5        AllowOverride All
 6        Options FollowSymLinks MultiViews
 8        <IfModule mod_dav.c>
 9                Dav off
10        </IfModule>
13<IfModule mod_ssl.c>
15    <VirtualHost>
17        ServerAdmin
18        ServerName
20        DocumentRoot /var/www/nextcloud
22        ErrorLog ${APACHE_LOG_DIR}/error.log
23        CustomLog ${APACHE_LOG_DIR}/access.log combined
25        SSLEngine on
26        SSLCertificateFile      /etc/ssl/certs/
27        SSLCertificateKeyFile   /etc/ssl/private/
29        <FilesMatch "\.(cgi|shtml|phtml|php)$">
30            SSLOptions +StdEnvVars
31        </FilesMatch>
32        <Directory /usr/lib/cgi-bin>
33            SSLOptions +StdEnvVars
34        </Directory>
35    </VirtualHost>

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


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 --redirect -d

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

        <VirtualHost *:80>
           Redirect permanent /

This just redirects all incoming http traffic to https.