Setting up NextCloud


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

sudo apt install apache2 mariadb-server libapache2-mod-php unzip

sudo 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):

cd /var/www
sudo wget
sudo unzip

Prepare the database

sudo mysql
CREATE USER 'nextcloud' IDENTIFIED BY 'nextcloud';
GRANT 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

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

Configure next cloud

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

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

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

Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews

        <IfModule mod_dav.c>
                Dav off

<IfModule mod_ssl.c>



        DocumentRoot /var/www/nextcloud

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLEngine on
        SSLCertificateFile      /etc/ssl/certs/
        SSLCertificateKeyFile   /etc/ssl/private/

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
        <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars

Finally enable nextcloud

Well enable nextcloud and restart apache:

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

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


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

crontab -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

apt-get install certbot python3-certbot-apache

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

certbot --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.