Installation

Update the repositories, install Apache, MySQL and Unzip

#Update the repositories
sudo apt update

#Install apache2
sudo apt install apache2

#Install mysql-server
sudo apt install mysql-server

#Install unzip (will be needed later)
sudo apt install unzip

Secure MySQL database

#Secure the mysql-server repositories
sudo mysql_secure_installation
VALIDATE PASSWORD COMPONENT: n
New root passwort: <YOUR MYSQL PASSWORD>
Re-enter new password: <YOUR MYSQL PASSWORD>
Remove anonymous user: y
Disallow root login remotely: y
Remove test database and access to it: y
Reload privileges tables now: y

Prepare MySQL database for Nextcloud

#Accessing the mysql-shell as root
sudo mysql -u root -p
<YOUR MYSQL PASSWORD>

#If you enter the mysql-shell as root, execute the following sql-commands
mysql> create database nextcloud;
mysql> create user 'nextcloud'@'localhost' identified by 'PASSWORD';
mysql> grant all privileges on nextcloud.* to 'nextcloud'@'localhost';
mysql> flush privileges;
mysql> quit

Install PHP for Nextcloud

#For nextcloud to work, install the latest version of PHP and a few PHP libraries
sudo apt install php7.4
sudo apt install php7.4-gd php7.4-mysql php7.4-curl php7.4-mbstring
sudo apt install php7.4-intl php7.4-gmp php7.4-bcmath php7.4-xml
sudo apt install libapache2-mod-php7.4 php7.4-zip php-imagick php-apcu

Download Nextcloud Hub 21 (on the following website)

  • Click on "Get Nextcloud"

  • Click on "Server packages"

  • Right-click on "Download Nextcloud"

  • Click on "Copy link address"

#Download the latest version of Nextcloud directly on your server
wget https://download.nextcloud.com/server/releases/nextcloud-21.0.0.zip

#Unzip the nextcloud-zip-file into the www directory of Apache
sudo unzip nextcloud-21.0.0.zip -d /var/www

#Switch to the directory of Apache
cd /var/www

#Change ownership of the nextcloud-folder to Apache (which is the "www-data" user)
sudo chown -R www-data:www-data nextcloud/

Configure Apache for Nextcloud

#Enable a few Apache modifications for Nextcloud
sudo a2enmod headers env dir mime rewrite

#Restart apache2
sudo service apache2 restart

Now, I am here

#Switch to the directory of the default Apache configuration
cd /etc/apache2/sites-available

#Open the 000-default.conf-file with nano to edit it
sudo nano 000-default.conf

#File: /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>

    DocumentRoot /var/www/nextcloud
    ServerName 10.100.1.179

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

        <IfModule mod_dav.c>
            Dav off
        </IfModule>

    </Directory>

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

</VirtualHost>
#Restart apache2 again
sudo service apache2 restart

#Enter the following command to show the local ip address of the server 
hostname -I | awk '{print $1}'

Nextcloud configuration

It's important to set up a static local ip address for your server, which you can do in your router's configuration:

#Switch the directory to the config.php file 
cd /var/www/nextcloud/config

#If there is no file create a new file called: config.php with the following command
sudo nano config.php
#Edit the content of the config.php file
<?php
$CONFIG = array (
        'trusted_domains' =>
        array (
          0 => '10.100.1.179', #ip address of your server and/or domainname
        ), 
); 
#Change owner of the config.php file
sudo chown www-data:root config.php

#Change the authorization of the config.php file
sudo chmod 777 config.php

Last updated