How to: Nextcloud installation with NFS mount

From Thomas-Krenn-Wiki
Jump to navigation Jump to search

This article describes the installation of Nextcloud as well as the implementation of an external storage medium in Nextcloud for the storage of data. In addition to Nextcloud, there is also MariaDB, Apache as well as PHP needed for the configuration. If you have already installed one of the packages, you can skip this step. This article shows the installation of the webserver without SSL encryption.

The advantages, which result from this, are different depending on the purpose:

  • better and easier scaling
  • less storage required in the host
  • data security

Requirements

The following requirements are recommended for the best performance and stability:

  • Ubuntu 24.04 LTS
    • 4 vCPUs
    • 4096 MB RAM
    • 15 GiB storage
  • MariaDB 10.11 or 11.4
  • Apache 2.4 with mod_php
  • PHP 8.2 or latest

In our example, the external storage is a NFS share with 50 GiB.

Installation of required packages

The installation starts with MariaDB and PHP. If you have already set this up, you can start with the Nextcloud installation.

MariaDB

In the beginning, the MariaDB package must be downloaded and installed:

root@sm-Nextcloud-Wiki-02:~# apt update && apt upgrade -y && apt install mariadb-server -y

For a new MariaDB installation, the next step is to execute the configuration script provided:

root@sm-Nextcloud-Wiki-02:~# sudo mysql_secure_installation

This leads to a series of prompts in which you, if desired, can make changes of the security options of your MariaDB installation.

In the first step, a root password is requested, as there is no password configured via default. Click ENTER to state "none".

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, you'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

After this, there is a request if you want to switch to the unix socket authentication. Under Ubuntu, the root account for MariaDB is closely linked to automatic system maintenance so that the configured authentication methods cannot be changed for this profile. Type in "n" and then press ENTER.

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n

You will be asked at the next prompt if you want to set up a root password for the data base. If this is not desired, type in "n" and then click on ENTER.

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] n

Apache 2.4

Apache can be installed with the following command:

root@sm-Nextcloud-Wiki-02:~# apt install apache2

There are three predefined profiles for Apache in total:

  • Apache: This profile only opens port 80 (unencrypted web traffic)
  • Apache Full: This profile opens port 80 (unencrypted web traffic) as well as port 443 (TLS/SSL encrypted traffic)
  • Apache Secure: This profile only opens port 443 (TLS/SSL encrypted traffic)

It is recommended to activate the most restrictive profile. As there is no SSL configured for the server, "Apache" is used.

root@sm-Nextcloud-Wiki-02:~# ufw allow 'Apache'

After this, the configuration can be verified as follows:

root@sm-Nextcloud-Wiki-02:~# ufw status
state: active

To                         Action       From
--                         ------       ----
Apache                     ALLOW        Anywhere                  
Apache (v6)                ALLOW        Anywhere (v6)

In addition, the state of the webserver is verified as follows:

root@sm-Nextcloud-Wiki-02:~# systemctl status apache2
* apache2.service - The Apache HTTP Server
    Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
    Active: active (running) since Wed 2024-07-31 07:22:08 UTC; 10min ago
    Docs: https://httpd.apache.org/docs/2.4/
Main PID: 5400 (apache2)
    Tasks: 55 (limit: 154127)
    Memory: 5.5M (peak: 6.2M)
        CPU: 92ms
    CGroup: /system.slice/apache2.service
            |-5400 /usr/sbin/apache2 -k start
            |-5402 /usr/sbin/apache2 -k start
            `-5403 /usr/sbin/apache2 -k start

Jul 31 07:22:08 sm-Nextcloud-Wiki-02 systemd[1]: Starting apache2.service - The Apache HTTP Server...
Jul 31 07:22:08 sm-Nextcloud-Wiki-02 systemd[1]: Started apache2.service - The Apache HTTP Server.

Now, you can connect to http://your.server.ip/ via web.

Hypertext Preprocessor

PHP (Hypertext Preprocessor) is a widely used open source scripting language, which is particularly suitable for web development and can be embedded in HTML. With the release of PHP 8.3, developers gain access to new features, performance enhancements and bug fixes that can significantly improve your web applications.

Installation

With the following commands, you can install PHP and all required packages:

root@sm-Nextcloud-Wiki-02:~# apt install curl gpg gnupg2 software-properties-common ca-certificates apt-transport-https lsb-release -y
root@sm-Nextcloud-Wiki-02:~# apt install php -y

After a successful installation, you can verify the PHP version with the following command.

root@sm-Nextcloud-Wiki-02:~# php --version
PHP 8.3.9 (cli) (built: Jul  5 2024 12:04:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.9, Copyright (c) Zend Technologies
with Zend OPcache v8.3.9, Copyright (c), by Zend Technologies

Additional functions

For the use of PHP with regard to Nextcloud, further extensions are required. These are installed as follows:

root@sm-Nextcloud-Wiki-02:~# apt install -y php-{cli,mysql,zip,gd,mbstring,curl,xml,bcmath,common,common,xml,intl,smbclient,gmp,memcached,imagick}

Configuration of basic packages

MariaDB - user and DB creation

After the successful configuration, a data base and its user must be created for Nextcloud.

To do this, log in to MariaDB:

root@sm-Nextcloud-Wiki-02:~# mysql

Now, a data base must be created. In this example, we use the name: nextclouddb

MariaDB> create database nextclouddb;

After this, a user must be created. In this example, the user nextcloud is created with all rights for nextclouddb

MariaDB> grant all privileges on nextclouddb.* TO 'nextcloud'@'%' identified by 'Password';

After the MariaDB Grant chart has been changed, execute the following command to adopt the changes and then leave the MariaDB command line.

MariaDB> flush privileges;
MariaDB> exit;

Webserver

For this, the configuration file nextcloud.conf in /etc/apache2/sites-available is created.

root@sm-Nextcloud-Wiki-02:~# nano /etc/apache2/sites-available/nextcloud.conf

In the following, there are two possibilities to configure the webserver:

1. Register based installation (for example: example.com/nextcloud)

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

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

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

2. Virtual host installation (Subdomain for example: cloud.example.com)

hint: If you have chosen Apache Full or Apache Secure before, the ports must be adjusted accordingly!

<VirtualHost *:80>
    DocumentRoot /var/www/nextcloud/
    ServerName  cloud.example.com

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

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

After the configuration has been adapted, you can activate it and restart Apache:

root@sm-Nextcloud-Wiki-02:~# a2ensite nextcloud.conf
root@sm-Nextcloud-Wiki-02:~# a2enmod rewrite headers env dir mime

root@sm-Nextcloud-Wiki-02:~# service apache2 restart

NextCloud

In the beginning, an external drive or a NFS share must be installed for Nextcloud. If you have already mounted a drive or a NAS, you can skip the step "mounting of NFS shares".

Mounting of NFS shares

Installation of nfs-common:

root@sm-Nextcloud-Wiki-02:~# apt install nfs-common -y

With the following commands, a register is created, which will be mounted afterwards:

root@sm-Nextcloud-Wiki-02:~# mkdir -p /mnt/nfs/tns
root@sm-Nextcloud-Wiki-02:~# mount your.host.ip:your/share/ /mnt/nfs/tns

For the installation of Nextcloud, an additional register must be created.

root@sm-Nextcloud-Wiki-02:~# mkdir /mnt/nfs/tns/nextcloud

The settings of the rights for the created register can only be made by the NFS host. The realization of it depends on the NFS host.

The documentation of the corresponding tools, for example NFS server, TrueNAS, FreeNAS, Synology, OpenMediaVault and much more, is helpful.

Installation of Nextcloud

Creation of register for web data:

root@sm-Nextcloud-Wiki-02:~# mkdir /var/www/nextcloud

Download of the web installer and setting of rights:

root@sm-Nextcloud-Wiki-02:~# cd /var/www/nextcloud
root@sm-Nextcloud-Wiki-02:~# wget https://download.nextcloud.com/server/installer/setup-nextcloud.php
root@sm-Nextcloud-Wiki-02:~# chown -R www-data:www-data /var/www/nextcloud

Now, the setup wizzard can be called up in the browser: http://your.server.ip/nextcloud/setup-nextcloud.php

After a successful installation, a cron job must be set for the background worker. For this, open the following file and add this line:

root@sm-Nextcloud-Wiki-02:~# crontab -u www-data -e

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


Verification:

root@sm-Nextcloud-Wiki-02:~# crontab -u www-data -l
[snip]
*/5  *  *  *  * php -f /var/www/nextcloud/cron.php

Additional configurations

Pretty URLs

Pretty URLs remove the index.php part in all Nextcloud URLs, for example for sharing links such as https://example.org/nextcloud/index.php/s/Sv1b7krAUqmF8QQ, which makes the URLs shorter and clearer.

To do this, two variables must be set in the following file:

root@sm-Nextcloud-Wiki-02:~# nano /var/www/nextcloud/config/config.php

'overwrite.cli.url' => 'https://example.org/nextcloud',
'htaccess.RewriteBase' => '/nextcloud',

The configuration file .htaccess must then be updated.

root@sm-Nextcloud-Wiki-02:~# sudo -u www-data php /var/www/nextcloud/occ maintenance:update:htaccess

Now index.php should no longer be displayed in the URL.

SSL (Self-Signed)

The Apache webserver, which is installed under Ubuntu, does already have a self issued certificate. You only have to activate the SSL module and the standard site.

Open a terminal and perform the following:

root@sm-Nextcloud-Wiki-02:~# a2enmod ssl
root@sm-Nextcloud-Wiki-02:~# a2ensite default-ssl
root@sm-Nextcloud-Wiki-02:~# service apache2 reload

Your Nextcloud server has now been successfully set up and you can start storing your data.


Translator: Alina Ranzinger

Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.


Related articles

Function of the Network Data Management Protocol NDMP
Open Source Release dates 2024
Registration of partner products