Installation
Installation des Apache und MySQL Servers
Mit dem folgenden Befehl wird der Apache und MySQL Server sowie einige von Nextcloud benötigte Pakete installiert:
1 |
sudo apt install -y mariadb-server mariadb-client apache2 apache2-utils php-cli php-common php-mbstring php-gd php-imagick php-intl php-bz2 php-xml php-mysql php-zip php-dev php-curl php-fpm php-dompdf redis-server php-redis php-smbclient php-ldap wget curl sudo unzip |
MySQL Datenbank Setupscript für Mariadatenbanken ausführen:
1 |
sudo mysql_secure_installation |
Ausgabe des Setupscripts:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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, we’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): 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] y New password:your-password Re-enter new password:your-password Password updated successfully! Reloading privilege tables.. … Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y … Success! Normally, root should only be allowed to connect from ‚localhost‘. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y … Success! By default, MariaDB comes with a database named ‚test‘ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y – Dropping test database… … Success! – Removing privileges on test database… … Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y … Success! Cleaning up… All done! If you’ve completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! |
Nextcloud benötigt einige Apache Module sowie das php-fpm Modul. Diese werden wie folgt aktiviert:
1 |
a2enmod proxy_fcgi setenvif mpm_event rewrite headers env dir mime ssl http2 |
und danach das PHP-FPM Modul:
1 |
a2enconf php7.4-fpm |
Installation der Nextcloud Software
Die Nextcloudsoftware ( v23) kann von der Nextcloud Webseite heruntergeladen werden und wird anschließend in das Webserververzeichnis entpackt und der Zugriff für den Webserver (www-data) gesetzt:
1 2 3 4 |
cd /var/www/ sudo wget https://download.nextcloud.com/server/releases/nextcloud-23.0.0.zip sudo unzip nextcloud-23.0.0.zip sudo chown -R www-data.www-data nextcloud |
Installation der SSL Software Certbot
Die Verwaltung von SSL Zertifikaten übernimmt der LetsEncrypt Certbot mit Hilfe des Apache Plugins.
1 |
sudo apt install python3-certbot-apache certbot |
Konfiguration
Nachdem die Benötigten Pakete sowie Nextcloud installiert und die Webservermodule eingerichtet sind erfolgt nun die Konfiguration des Apache Webserver sowie die Konfiguration von Nextcloud.
Apache Konfiguration
Die grundlegende Apache Konfiguration wird in der Datei /etc/apache2/apache2.conf
vorgenommen. Hier müssen folgende Einträge zum Lesen der .htaccess Dateien geändert werden:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
zu:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Um HTTP/2 zu aktivieren muss die /etc/apache2/apache2.conf
Datei um folgende Zeile ergänzt werden:
1 |
Protocols h2 h2c http/1.1 |
Damit die Nextcloud Dateien (/var/www/nextclod) mit dem Apache Webserver verarbeitet werden können, muss hierzu eine Apache Konfigurationsdatei erstellt werden. Die Konfigurationsdateien für Webseiten befinden sich im Verzeichnis /etc/apache/sites-available. Innerhalb dieses Verzeichnisses wird dann die Nextcloud Webseiten Konfiguration (/etc/apache2/sites-available/nextcloud.conf) mit folgendem Inhalt erstellt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Alias /nextcloud "/var/www/nextcloud/" <Directory /var/www/nextcloud/> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /var/www/nextcloud SetEnv HTTP_HOME /var/www/nextcloud <IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=15552000;$ </IfModule> </Directory> |
Damit ist die Apache Konfiguration abgeschlossen.
PHP Konfiguration
Als nächstes wird PHP für die Verwendung von Nextcloud eingerichtet. Die PHP (v7.4) Konfiguration ist in der Datei /etc/php/7.4/fpm/php.ini
enthalten. Welche PHP Konfigurationsdatei aktuell geladen wurde kann mit folgendem Befehl angezeigt werden:
1 |
php -i | grep "Loaded Configuration File" |
Anpassung folgender Parameter für PHP interne Prozesse:
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
Anpassung folgender Parameter für PHP externe Funktionen:
max_execution_time = 300
max_input_time = 600
memory_limit = 512M
upload_max_filesize = 10240M
Danach wird der Apache Webserver und PHP-fpm neu gestartet:
1 |
sudo systemctl restart apache2 php7.4-fpm |
Datenbank Konfiguration
Nextcloud benötigt eine SQL Datenbank. Dazu wird ein Datenbenutzer ( nextcloud_user ) mit dem dazugehörigen Passwort ( password ) sowie die Datenbank ( nextcloud_db1 ) mit folgendem Befehl erstellt:
1 |
sudo mysql -e " create database nextcloud_db1; create user nextcloud_user1@localhost identified by 'password'; grant all privileges on nextcloud_db1.* to nextcloud_user1@localhost; flush privileges;" |
Die Datenbank samt Benutzer und Passwort kann alternativ mit einem grafischen Werkzeug wie beispielsweise phpmyadmin erstellt werden.
Somit ist alles für die abschließende Einrichtung der Nextcloud Software eingerichtet und die finale Konfiguration kann nun über den Browser erfolgen. Ein Aufruf ( http://<URL/ServerIP>/nextcloud) der Server URL/IP gefolgt von dem in der Datei /etc/apache2/sites-available/nextcloud.conf definierten Apache Alias ( Alias /nextcloud “/var/www/nextcloud/”) verweist nun auf das Nextcloud Installations Interface/Webseite. Hier wird das Nextcloud Administrator Konto erstellt sowie der Datenbankzugriff konfiguriert und die Datenbank mit den Nextcloud spezifischen Daten erstellt.
Terminal Befehle
Nextcloud erfordert unter Umständen, wie z.B. dem Ausfall des Webinterfaces einige Terminaleingaben. Die wichtigsten sind im Folgenden gelistet:
- Datenverzeichnis aller User neu einlesen :
1sudo -u www-data php /var/www/nextcloud/console.php files:scan --all - Datenverzeichnis einzelner User neu einlesen :
1sudo -u www-data php /var/www/nextcloud/console.php files:scan Nutzername - Nextcloud update via Terminal :
1sudo -u www-data php /var/www/nextcloud/updater/updater.phar
oder
1sudo -u www-data php /var/www/nextcloud/occ upgrade - Maintenance Modus / Nextcloud-Online-Updater zurücksetzen
1sudo -u www-data php /var/www/nextcloud/occ maintenance:repair
Tipps und Tricks
-
-
Zugriff auf das Hostdateisystem
Mit der “External storage support ” Erweiterung ist der Zugriff auf lokale oder entfernte Dateisysteme möglich. Für den lokalen Zugriff müssen jedoch die Rechte der entsprechenden Verzeichnisse korrekt gesetzt sein. Soll beispielsweise der Lese sowie Schreibzugriff auf das Verzeichnis /home/user/Archiv über das Nextcloud Webinterface gewährt werden, müssen Lese-, und Schreibrechte auf das Verzeichniss für den Webserverbenutzer (www-data) ermöglicht werden:
1sudo chown -R www-data.www-data /home/user/ArchivUm dem Benutzer <user> ebenfalls vollen Zugriff auf das Verzeichnis /home/user/Archiv zu gewähren, muss Dieser der Gruppe www-data hinzugefügt werden
1sudo adduser user www-dataund Lese-, sowie Schreibrechte sämtlicher Verzeichnisse und Dateien innhalb von /home/user/Archiv für den Besitzer (www-data) und die Gruppe (www-data) gewährt werden
12sudo chmod -R 775 /home/user/Archiv # für Verzeichnisse und Dateiensudo chmod -R 664 /home/user/Archiv # für nicht auszuführende Dateien, sicherer als 775ACHTUNG ! Vollzugriff des Webserverbenutzers auf Verzeichnisstrukuren außerhalb des Verzeichnisses /var/www können ein Sicherheitsrikio darstellen
-
Nextcloud-Online-Updater zurücksetzen
Mit unter kann es passieren das ein Nextcloud Update nicht korrekt durchläuft und bei einem Schritt (step) hängen bleibt. Es gibt zwei Möglichkeiten den Updateprozesse zurückzusezten:
-
-
-
- 1. Shellbefehl : sudo -u www-data php /var/www/nextcloud/occ maintenance:repair
- 2. den Ordner /var/www/nextcloud/updater-<various string> komplett löschen
-
Sonstiges
Externe Datenverzeichnisse in nextcloud automatisch einlesen : https://decatec.de/home-server/nextcloud-direkter-zugriff-auf-dateien-ueber-das-dateisystem/
Nextcloud v21 installieren und updaten : https://www.c-rieger.de/manuelles-nextcloud-upgrade/
by Speefak | www.markus-blog.de | https://docs.nextcloud.com | www.c-rieger.de