Nextcloud – Installation Script for Linux Systems

This script was prepared for a clean (minimal) installation of Linux systems such as:
Debian 11/12, Entepreise Linux 9, Ubuntu Server 22, Fedora Server 39 on AMD64 (x86_64) processor architecture.
It will update OS, install neeeded packages, and preconfigure everything to run Nextcloud.
There are Apache (web server), MariaDB (database server), PHP (programming language),
NTP (time synchronization service), and Redis (cache server) used.
Also new service for Nextcloud cron is generated that starts every 5 minutes.
A new user with administrative privileges will be added to the Nextcloud, you will find his credentials after the script runs (the password is randomly generated).

After install You may use Your web browser to access Nextcloud using local IP address.
Both HTTP and HTTPS protocols are enabled by default (localhost certificate is generated).
If you already have a domain you want to use then you can do so by adding it as an argument to the command that runs the script. Remember, however, that the domain must first be set to your server's IP address, and your network devices (routers) must already be properly configured. Otherwise, SSL certificate generation will fail.

Script link: https://github.com/nicrame/Linux-Scripts/blob/master/nextcloud-debian-ins.sh

To install use this command:

sudo sh -c "wget -q https://github.com/nicrame/Linux-Scripts/raw/master/nextcloud-ins.sh && chmod +x nextcloud-ins.sh && ./nextcloud-ins.sh"

Or if You already got domain name configured:

sudo sh -c "wget -q https://github.com/nicrame/Linux-Scripts/raw/master/nextcloud-ins.sh && chmod +x nextcloud-ins.sh && ./nextcloud-ins.sh -dm=mojadomena.com"

All available script arguments (you may or may not need to add to the startup command):
-lang – support for multiple languages, currently available: Arabic (ar), Chinese (zh), French (fr), Hindi (hi), Polish (pl), Spanish (es) and Ukrainian (uk). An option left undefined will simply not add system packages and will not pre-configure Nextcloud (the default web browser language will be used).
-mail – the email address of the administrative account.
-dm – the domain you want to use, the script will configure the web server to make the domain point to Nextcloud, add it as a trusted address for NC itself, and configure the SSL (Let's encrypt) certificate service to make a secure httpS connection work. The domain must already be pre-configured i.e. pointing to the IP address where we are providing the service. The router should also already be pre-configured (that is, redirect traffic from outside to port 80 and 443 of the server on which Nextcloud is running).
-nv – the version of Nextcloud we want to use. Versions available are 24, 25, 26, and 27. Older versions have customized PHP installation and configuration to match the NC version. No option selected will install the latest version of the script for the moment.

Be sure to define arguments after the sum sign (=).

Example use of the script with all options:

sudo sh -c "wget -q https://github.com/nicrame/Linux-Scripts/raw/master/nextcloud-ins.sh && chmod +x nextcloud-ins.sh && ./nextcloud-ins.sh -lang=pl -mail=[email protected] -dm=mojadomena.com -nv=24"

It was tested with Nextcloud v24-V28.

Changelog:
V 1.8.1 – 07.02.2024
– first release with Fedora Server 39, and Ubuntu Server LTS (22) distributions support
V 1.8 – 04.02.2024
– first release with Rocky Linux (9), and other Enterprise Linux distributions support
– a little more code optimizations
V 1.7.1 – 01.02.2024
– code cleanup
– add maintenance window start time configuration (for 28.0.2 released today)
V 1.7 – 30.01.2024
– tweaks for thumbnails/preview generation
– disabe sleep/hibernate modes in OS
– add HTTP2 protocol support
– small security fix
– description improvements
– packages installer will now wait for background jobs (started by OS) to finish
V 1.6.4 – 04.01.2024
– add bz2 module for PHP (for Nextcloud Hub 7)
– Happy New Year!
V 1.6.3 – 04.11.2023
– more tests and fixes
V 1.6.2 – 04.08.2023
– few more languages are now supported with -lang= parameter (Arabic (ar), Chinese (zh), French (fr), Hindi (hi), Polish (pl), Spanish (es) and Ukrainian (uk))
V 1.6.1 – 03.08.2023
– small tweaks
V 1.6 – 03.08.2023
– new variable that allows installing older version of Nextcloud (users reported problems with NC27)
– the script rename itself after finished work (so installer command always refer to newest version)
– script is prepared now for few future updates (up to Nextcloud v28)
V 1.5.5 – 12.07.2023
– better description of variables use on error.
V 1.5.4 – 07.07.2023
– fixed some logical problem
– add support for Debian 12
– add support for Nextcloud Hub 5 (v27)
V 1.5.3 – 15.04.2023
– using older PHP (8.1) version for upgrade process before removing it (Nextcloud do not finish upgrade process on never PHP version)
– check for currently installed Nextcloud version and update it so many times it needs (till version 26) – when upgrading from script version 1.4 or older
V 1.5.2 – 05.04.2023
– twofactor_webauthn app installing and enabling for more security (tested with Yubikey)
V 1.5.1 – 05.04.2023
– upgrading from 1.4 and lower added to the script
V 1.5 – 25.03.2023
– use Nextcloud Hub 4 (v26)
– enable opcache again (it looks it's working fine now)
– use PHP version 8.2
– install ddclient (dynamic DNS client – https://ddclient.net/)
– install miniupnpc ans start it for port 80 and 443 to open ports (it should be unncessary)
– added more variables to use (language, e_mail)
– installer is now creating file with it's version number for future upgrades
– installer detects if older versions of script were used, and in the next release it will upgrade everything (nextcloud included)
V 1.4.3 – 24.02.2023
– allow self-signed certificate config option in nextcloud (it may be needed sometimes)
V 1.4.2 – 10.02.2023
– completely disable opcache because of many segfaults even when JIT is completely disabled
V 1.4.1 – 08.02.2023
– opcache jit cache in php has been disabled because of many segfaults reported
V 1.4 – 31.01.2023
– fixes thanks to "maybe" user from hejto.pl portal (ufw, redis, chmods etc.) Thank You!
V 1.3 – 30.01.2023
– fix PHP 8.1 installing
– more data stored to log for better error handling
V 1.2 – 23.01.2023
– some performance fixes (better support for large files)
V 1.1 – 04.08.2022
– added support for adding domain name as command line argument (with let's ecnrypt support)
– added crontab job for certbot (Let's encrypt) and some more description
V 1.0 – 20.06.2022
– initial version based on private install script (for EL)