| Nächste Überarbeitung | Vorherige Überarbeitung |
| nextcloud [2021/12/15 17:59] – angelegt noone | nextcloud [2021/12/15 20:37] (aktuell) – noone |
|---|
| ==Nextcloud 18 fehlerlos und automatisch installieren.== | ==Nextcloud 18 fehlerlos und automatisch installieren.== |
| |
| # Eure Daten Username,Passwort,Pfad usw eintragen. Wird für die automatische Installation benötigt. Falls ihr Befehl für Befehl in die Bash kopiert, müsst ihr die Daten auch Zeile für Zeile in die bash kopieren und Enter drücken. Ohne das funktioniert es nicht, da alles dynamisch zur Selbstanpassung geschrieben wurde. | Eure Daten |
| | * Username |
| | * Passwort |
| | * Pfad usw. |
| | eintragen. Wird für die automatische Installation benötigt. |
| | Falls ihr Befehl für Befehl in die Bash kopiert, müsst ihr die Daten auch Zeile für Zeile in die |
| | bash kopieren und Enter drücken. Ohne das funktioniert es nicht, da alles dynamisch zur Selbstanpassung |
| | geschrieben wurde. |
| ############################################################## | ############################################################## |
| # MySQL Daten | # MySQL Daten |
| auser=Benutzername | auser=Benutzername |
| apass=Benutzerpasswort | apass=Benutzerpasswort |
| adir=/var/www/nextcloud # müsste passen 🙂 | adir=/var/www/html/nextcloud # müsste passen 🙂 |
| trust=raspberrypi # müsste passen 🙂 | trust=raspberrypi # müsste passen 🙂 |
| trust1=Euer DynDNS | trust1=Euer DynDNS |
| | ddir=$adir/data # Datenverzeichnis anpassen (ausserhalt Web-Daten) |
| ############################################################## | ############################################################## |
| | |
| # mit root anmelden | # mit root anmelden |
| sudo -i | sudo -i |
| | |
| # PHP Repo hinzufügen | # PHP Repo hinzufügen |
| wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add - | wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add - echo "deb https://packages.sury.org/php/ buster main" | tee /etc/apt/sources.list.d/php.list |
| echo "deb https://packages.sury.org/php/ buster main" | tee /etc/apt/sources.list.d/php.list | |
| | # Zuerst einmal updaten, da wir das PHP Repo hinzugefügt haben. |
| # Zuerst einmal updaten, da wir das PHP Repo hinzugefügt haben. | apt update -y && apt upgrade -y |
| apt update -y && apt upgrade -y | |
| | # Apache und Mysql installieren |
| # Apache und Mysql installieren | apt install apache2 mariadb-server zip unzip apt-transport-https libmariadb-dev-compat libmariadb-dev libapache2-mod-security2 imagemagick |
| apt install apache2 mariadb-server zip unzip apt-transport-https \ | |
| libmariadb-dev-compat libmariadb-dev libapache2-mod-security2 \ | # PHP 7.4 und benötigte Module installieren |
| imagemagick | apt install php7.4-fpm php7.4-gd php7.4-mysql php7.4-curl php7.4-zip php7.4-intl libapache2-mod-php7.4 php7.4-mbstring php7.4-bz2 php7.4-cli php7.4-common php7.4-ssh2 php7.4-sqlite3 php7.4-xml php7.4-json php7.4 php-apcu php-imagick |
| | |
| # PHP 7.3 und benötigte Module installieren | # Eine Seite für Apache erstellen |
| apt install php7.3-fpm php7.3-gd php7.3-mysql php7.3-curl \ | cat <<EOF > /etc/apache2/sites-available/nextcloud.conf |
| php7.3-zip php7.3-intl libapache2-mod-php7.3 php7.3-mbstring \ | <VirtualHost *:443> |
| php7.3-bz2 php7.3-cli php7.3-common php7.3-ssh2 php7.3-sqlite3 \ | ServerName localhost # Ersetzt localhost mit euren dyndns |
| php7.3-xml php7.3-json php7.3 php-apcu php-imagick | ServerAdmin webmaster@localhost |
| | |
| # Eine Seite für Apache erstellen | |
| cat <<EOF > /etc/apache2/sites-available/nextcloud.conf | |
| <VirtualHost *:443> | |
| ServerName localhost # Ersetzt localhost mit euren dyndns | |
| ServerAdmin webmaster@localhost | |
| | |
| DocumentRoot $adir | DocumentRoot $adir |
| ProxyErrorOverride on | ProxyErrorOverride on |
| | |
| <If "-f %{SCRIPT_FILENAME}"> | <If "-f %{SCRIPT_FILENAME}"> |
| SetHandler "proxy:unix:/run/php/php7.3-fpm.sock|fcgi://localhost" | SetHandler "proxy:unix:/run/php/php7.3-fpm.sock|fcgi://localhost" |
| </If> | </If> |
| | |
| LogLevel warn | LogLevel warn |
| ErrorLog \${APACHE_LOG_DIR}/error.log | ErrorLog \${APACHE_LOG_DIR}/error.log |
| CustomLog \${APACHE_LOG_DIR}/access.log combined | CustomLog \${APACHE_LOG_DIR}/access.log combined |
| | |
| <Directory /var/www> | <Directory /var/www> |
| Options Indexes FollowSymLinks | Options Indexes FollowSymLinks |
| AllowOverride All | AllowOverride All |
| Require all granted | Require all granted |
| </Directory> | </Directory> |
| | |
| Redirect 301 /.well-known/carddav /remote.php/dav | Redirect 301 /.well-known/carddav /remote.php/dav |
| Redirect 301 /.well-known/caldav /remote.php/dav | Redirect 301 /.well-known/caldav /remote.php/dav |
| | |
| <IfModule mod_headers.c> | <IfModule mod_headers.c> |
| Header always set Strict-Transport-Security "max-age=15552000; inextcloudludeSubDomains" | Header always set Strict-Transport-Security "max-age=15552000; inextcloudludeSubDomains" |
| Header always set Referrer-Policy "no-referrer" | Header always set Referrer-Policy "no-referrer" |
| </IfModule> | </IfModule> |
| | |
| </VirtualHost> | </VirtualHost> |
| EOF | EOF |
| | |
| # Nextcloud Apache Seite aktivieren | # Nextcloud Apache Seite aktivieren |
| a2ensite nextcloud.conf | a2ensite nextcloud.conf |
| | |
| # Apache module aktivieren | # Apache module aktivieren |
| a2enmod headers proxy_fcgi proxy_balancer proxy proxy_http | a2enmod headers proxy_fcgi proxy_balancer proxy proxy_http |
| | |
| # Apache neu starten | # Apache neu starten |
| service apache2 restart | service apache2 restart |
| | |
| # Wenn ihr dyndns benutzt, letsencrypt SSL installieren | # Wenn ihr dyndns benutzt, letsencrypt SSL installieren |
| apt install python3-certbot-apache | apt install python3-certbot-apache |
| certbot -d "euer dyndns" --apache | certbot -d "euer dyndns" --apache |
| | |
| # Apache erneut neu starten | # Apache erneut neu starten |
| service apache2 restart | service apache2 restart |
| | |
| # MySQL (MariaDB) vorbereiten | # MySQL (MariaDB) vorbereiten |
| mysql_secure_installation | mysql_secure_installation |
| | |
| # MySQL starten | # MySQL starten |
| systemctl start mysql | systemctl start mysql |
| | |
| # MySQL Datenbank anlegen | # MySQL Datenbank anlegen |
| mysql -u root -p$root_pw -e "CREATE DATABASE $database;" | mysql -u root -p$root_pw -e "CREATE DATABASE $database;" |
| | |
| # MySQL User anlegen und die Rechte vergeben | # MySQL User anlegen und die Rechte vergeben |
| mysql -u root -p$root_pw -e "CREATE USER '$sql_user'@'%' IDENTIFIED BY '$sql_user_pw'; \ | mysql -u root -p$root_pw -e "CREATE USER '$sql_user'@'%' IDENTIFIED BY '$sql_user_pw'; \ |
| GRANT ALL PRIVILEGES ON $database.* TO '$sql_user'@'localhost';FLUSH PRIVILEGES;" | GRANT ALL PRIVILEGES ON $database.* TO '$sql_user'@'localhost';FLUSH PRIVILEGES;" |
| | |
| # Für Nextcloud müssen wir ein paar Einstellungen in der php.ini ändern | # Für Nextcloud müssen wir ein paar Einstellungen in der php.ini ändern |
| sed -i "s/memory_limit = 128M/memory_limit = 512M/" /etc/php/7.3/fpm/php.ini | sed -i "s/memory_limit = 128M/memory_limit = 512M/" /etc/php/7.4/fpm/php.ini |
| sed -i "s/;opcache.enable=.*/opcache.enable=1/" /etc/php/7.3/fpm/php.ini | sed -i "s/;opcache.enable=.*/opcache.enable=1/" /etc/php/7.4/fpm/php.ini |
| sed -i "s/;opcache.enable_cli=.*/opcache.enable_cli=1/" /etc/php/7.3/fpm/php.ini | sed -i "s/;opcache.enable_cli=.*/opcache.enable_cli=1/" /etc/php/7.4/fpm/php.ini |
| sed -i "s/;opcache.interned_strings_buffer=.*/opcache.interned_strings_buffer=8/" /etc/php/7.3/fpm/php.ini | sed -i "s/;opcache.interned_strings_buffer=.*/opcache.interned_strings_buffer=8/" /etc/php/7.4/fpm/php.ini |
| sed -i "s/;opcache.max_accelerated_files=.*/opcache.max_accelerated_files=10000/" /etc/php/7.3/fpm/php.ini | sed -i "s/;opcache.max_accelerated_files=.*/opcache.max_accelerated_files=10000/" /etc/php/7.4/fpm/php.ini |
| sed -i "s/;opcache.memory_consumption=.*/opcache.memory_consumption=128/" /etc/php/7.3/fpm/php.ini | sed -i "s/;opcache.memory_consumption=.*/opcache.memory_consumption=128/" /etc/php/7.4/fpm/php.ini |
| sed -i "s/;opcache.save_comments=.*/opcache.save_comments=1/" /etc/php/7.3/fpm/php.ini | sed -i "s/;opcache.save_comments=.*/opcache.save_comments=1/" /etc/php/7.4/fpm/php.ini |
| sed -i "s/;opcache.revalidate_freq=.*/opcache.revalidate_freq=1/" /etc/php/7.3/fpm/php.ini | sed -i "s/;opcache.revalidate_freq=.*/opcache.revalidate_freq=1/" /etc/php/7.4/fpm/php.ini |
| | |
| # PHP 7.3 und apache2 neu starten | # PHP 7.4 und apache2 neu starten |
| service php7.3-fpm restart | service php7.4-fpm restart |
| service apache2 restart | service apache2 restart |
| | |
| # Pfad festlegen – nicht ändern | # Pfad festlegen – nicht ändern |
| ddir=$adir/data | occ=$adir/occ |
| occ=$adir/occ | |
| | # Nextcloud herunter laden und entpacken |
| # Nextcloud herunter laden und entpacken | cd /var/www/html |
| cd /var/www | wget https://download.nextcloud.com/server/releases/latest.zip |
| wget https://download.nextcloud.com/server/releases/latest.zip | unzip latest.zip |
| unzip latest.zip | |
| | # Rechte auf den Webserver setzen |
| # Rechte auf den Webserver setzen | chown -R www-data:www-data /var/www |
| chown -R www-data:www-data /var/www | |
| | # Nextcloud automatisch installieren. Es kommt eine Meldung, wenn es erfolgreich war. |
| # Nextcloud automatisch installiere. Es kommt eine Meldung, wenn es erfolgreich war. | su - www-data -s /bin/bash -c "php $occ maintenance:install --database mysql \ |
| su - www-data -s /bin/bash -c "php $occ maintenance:install --database mysql \ | --database-name '$database' --database-user '$sql_user' --database-pass '$sql_user_pw' \ |
| --database-name '$database' --database-user '$sql_user' --database-pass '$sql_user_pw' \ | --admin-user '$auser' --admin-pass '$apass' --data-dir '$ddir'" |
| --admin-user '$auser' --admin-pass '$apass' --data-dir '$ddir'" | |
| | # Hostname und evtl DynDNS in die Einstellungen von Nextcloud |
| # Hostname und evtl DynDNS in den Einstellungen von Nextcloud | # schreiben. Ohne die habt ihr kein Zugriff auf Nextcloud |
| # schreiben. Ohne dem habt ihr kein Zugriff auf Nextcloud | sudo -u www-data php $occ config:system:set trusted_domains 0 --value=$trust |
| sudo -u www-data php $occ config:system:set trusted_domains 0 --value=$trust | sudo -u www-data php $occ config:system:set trusted_domains 0 --value=$trust1 |
| sudo -u www-data php $occ config:system:set trusted_domains 0 --value=$trust1 | sed -i "s/output_buffering=.*/output_buffering='Off'/" $adir/.user.ini |
| sed -i "s/output_buffering=.*/output_buffering='Off'/" $adir/.user.ini | |
| | # Cron aktivieren |
| # Cron aktivieren | sudo -u www-data php $occ background:cron |
| sudo -u www-data php $occ background:cron | |
| | # Memory Cache anlegen. Ohne dem kommt ein Fehler |
| # Memory Cache anlegen. Ohne dem kommt ein Fehler | sed -i '/);/d' $adir/config/config.php |
| sed -i '/);/d' $adir/config/config.php | cat <<EOF >>$adir/config/config.php |
| cat <<EOF >>$adir/config/config.php | 'logfile' => '$adir/nextcloud.log', |
| 'logfile' => '$adir/nextcloud.log', | 'logtimezone' => 'Europe/Berlin', |
| 'logtimezone' => 'Europe/Berlin', | 'memcache.local' => '\\OC\\Memcache\\APCu', |
| 'memcache.local' => '\\OC\\Memcache\\APCu', | ); |
| ); | EOF |
| EOF | |
| | # Apache stopen, um die Nextcloud Daten zu optimieren. Ist erforderlich. |
| # Apache stopen um die Nextcloud Daten zu optimieren. Ist erforderlich. | sudo service apache2 stop |
| service apache2 stop | sudo -u www-data php $occ db:add-missing-indices |
| sudo -u www-data php $occ db:add-missing-indices | sudo -u www-data php $occ db:convert-filecache-bigint |
| sudo -u www-data php $occ db:convert-filecache-bigint | sudo -u www-data php $adir/cron.php |
| sudo -u www-data php $adir/cron.php | |
| | # Cron anlegen |
| # Cron anlegen | crontab -u www-data -l ; echo "*/5 * * * * php -f $adir/cron.php > /dev/null 2>&1") | crontab -u www-data - |
| (crontab -u www-data -l ; echo "*/5 * * * * php -f $adir/cron.php > /dev/null 2>&1") | crontab -u www-data - | |
| | # Apache starten |
| # Apache starten | service apache2 start |
| service apache2 start | |
| | # MySQL Einstellungen für Nextcloud |
| # MySQL Einstellungen für Nextcloud | cat <<EOF > /etc/mysql/conf.d/mysql.cnf |
| cat <<EOF > /etc/mysql/conf.d/mysql.cnf | [mysql] |
| [mysql] | innodb_buffer_pool_size=1G |
| innodb_buffer_pool_size=1G | innodb_io_capacity=4000 |
| innodb_io_capacity=4000 | EOF |
| EOF | |
| | # MySQL restart |
| | service mysql restart |
| | |
| | # Fertig. Viel Spaß |
| |
| # MySQL restart | [[https://blog.gebert.it/nextcloud-18-mit-apache2-auf-dem-raspberry-pi-4-ohne-fehler-installieren/|Quelle]] |
| service mysql restart | |
| |
| # Fertig. Viel Spaß | |