apt install apache2 unzip mariadb-server mariadb-client php7.0-fpm php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl libapache2-mod-php7.0 php7.0-common php7.0-gd php7.0-json php7.0-curl php7.0-zip php7.0-xml php7.0-mbstring
mysql_secure_installation
mysql -u root -p

create database nextcloud;
create user BENUTZER@localhost identified by 'PASSWORD';
grant all privileges on nextcloud.* to BENUTZER@localhost identified by 'PASSWORD';
flush privileges;
exit;

cd /var/www
unzip /Pfad/Zum/NectCloud/Download
mkdir /var/www/nextcloud-data/
vi /etc/apache2/sites-available/nextcloud.conf

<VirtualHost *:80>
 DocumentRoot "/var/www/nextcloud"
 ServerName HOST.DOMAIN.DOM
<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
 Satisfy Any
</Directory>
</VirtualHost>

a2ensite nextcloud.conf
a2enmod rewrite && a2enmod headers && a2enmod env && a2enmod dir && a2enmod mime && a2enmod setenvif && a2enmod ssl
service apache2 restart
vi nextcloud.sh

#!/bin/bash
ocpath='/var/www/nextcloud'
htuser='www-data'
htgroup='www-data'
rootuser='root'
printf "Creating possible missing Directories\n"
mkdir -p $ocpath/data
mkdir -p $ocpath/assets
mkdir -p $ocpath/updater
printf "chmod Files and Directories\n"
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750
printf "chown Directories\n"
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/assets/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/updater/
chmod +x ${ocpath}/occ
printf "chmod/chown .htaccess\n"
if [ -f ${ocpath}/.htaccess ]
 then
  chmod 0644 ${ocpath}/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ]
 then
  chmod 0644 ${ocpath}/data/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi
chown www-data:www-data /var/www/nextcloud-data -R

chmod +x nextcloud.sh
./nextcloud.sh
systemctl daemon-reload
apt install letsencrypt python-letsencrypt-apache

letsencrypt --apache --agree-tos --email EMAIL@DOMAIN.DOM -d HOST.DOMAIN.DOM