Files
raspberry-pi/nextcloud.md
2018-08-18 11:47:51 +02:00

10 KiB

Nextcloud auf dem Raspberry Pi 3

Ersteinrichtung des Raspberry Pi

Siehe Ersteinrichtung

Vorbereitungen

vgl. Anleitung von AvoidErrors

Aktualisierung suchen & installieren

sudo apt update && sudo apt upgrade -y && sudo reboot

Benutzer www-data zur Gruppe www-data hinzufügen

sudo usermod -a -G www-data www-data

Benötigte Pakete installieren

sudo apt install apt-transport-https ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list

sudo apt update
sudo apt install php7.2 -y
sudo apt install php7.2-fpm php7.2-mysql php7.2-common php7.2-gd php7.2-json php7.2-cli php7.2-curl php7.2-xml php7.2-zip php7.2-mbstring php7.2-apcu -y

sudo update-rc.d apache2 disable
sudo reboot
suao apt install nginx -y

Eigenes SSL-Zertifikat erstellen

sudo openssl req $@ -new -x509 -days 730 -nodes -out /etc/nginx/cert.pem -keyout /etc/nginx/cert.key

Zugriffsrechte des Zertifikats ändern

sudo chmod 600 /etc/nginx/cert.pem  
sudo chmod 600 /etc/nginx/cert.key

Alte nginx config-Datei sichern

sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default_old

Neue config-Datei erstellen

sudo nano /etc/nginx/sites-available/default

Dort einfügen:
An 2 Stellen muss die IP-Adresse oder die dynamische DNS eingetragen werden! Außerdem müssen die Pfade zum SSL-Zertifikat und zu den Diffie-Hellman-Parametern geändert werden.

upstream php-handler {
    server 127.0.0.1:9000;
}

server {
    listen 80;
    server_name IP-Adresse oder dynamische DNS;
    # enforce https
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name IP-Adresse oder dynamische DNS;

    ssl_certificate /path/to/cert;
    ssl_certificate_key /path/to/private-key;

    # Security Headers
    add_header Strict-Transport-Security "max-age=15768000";
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /path/to/dhparams.pem;
    ssl_session_cache shared:ssl_session_cache:10m;

    # Path to the root of your installation
    root /var/www;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ \.php(?:$|/) {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_param modHeadersAvailable true;
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
    }

    location = /.well-known/carddav {
        return 301 $scheme://$host/nextcloud/remote.php/dav;
    }

    location = /.well-known/caldav {
        return 301 $scheme://$host/nextcloud/remote.php/dav;
    }

    location /.well-known/acme-challenge { }

    location ^~ /nextcloud {
        fastcgi_buffers 64 4K;

        # Disable gzip to avoid the removal of the ETag header
        gzip off;

        error_page 403 /nextcloud/core/templates/403.php;
        error_page 404 /nextcloud/core/templates/404.php;

        location /nextcloud {
            rewrite ^ /nextcloud/index.php$uri;
        }

        location ~ ^/nextcloud/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }

        location ~ ^/nextcloud/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }

        location ~ ^/nextcloud/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
            include fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;
            fastcgi_param modHeadersAvailable true;
            fastcgi_param front_controller_active true;
            fastcgi_pass php-handler;
            fastcgi_intercept_errors on;
        }

        location ~ ^/nextcloud/(?:updater|ocs-provider)(?:$|/) {
            try_files $uri/ =404;
            index index.php;
        }

        # Adding the cache control header for js and css files
        # Make sure it is BELOW the PHP block
        location ~* \.(?:css|js|woff|svg|gif)$ {
            try_files $uri /nextcloud/index.php$uri$is_args$args;
            add_header Cache-Control "public, max-age=7200";
            add_header X-Content-Type-Options nosniff;
            add_header X-Frame-Options "SAMEORIGIN";
            add_header X-XSS-Protection "1; mode=block";
            add_header X-Robots-Tag none;
            add_header X-Download-Options noopen;
            add_header X-Permitted-Cross-Domain-Policies none;
            access_log off;
        }

        location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ {
            try_files $uri /nextcloud/index.php$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
}

Nginx-Dateilimits für Upoads anheben

sudo nano /etc/nginx/nginx.conf

-> Dort im "http"-Abschnitt einfügen (oder verändern, wenn bereits vorhanden)

client_max_body_size 2048M;

PHP-conf bearbeiten

sudo nano /etc/php5/fpm/pool.d/www.conf  

-> listen = 127.0.0.1:9000

conf-swapsize ändern

sudo nano /etc/dphys-swapfile  

-> CONF_SWAPSIZE = 512

Pi neustarten
sudo reboot

Nextcloud installieren

Als Root anmelden

sudo -s

Verzeichnis wechseln

cd /var/www

Nextcloud laden

wget https://download.nextcloud.com/server/releases/nextcloud-xxx.tar.bz2

.tar entpacken

tar xvjf nextcloud-xxx.tar.bz2

User „www-data“ zum Eigentümer des Ordners machen

chown -R www-data:www-data /var/www/nextcloud

Alte Dateien entfernen

rm -rf nextcloud-xxx.tar.bz2
exit

Datenbank ändern (MySQL)

Benötigte Pakete installieren

sudo apt install mysql-server -y

MySQL einrichten

sudo mysql_secure_installation

Set root password: Y
Remove anonymous users: n
Disallow root login remotely: n
Remove test database and asccess to it: Y
Reload privilege tables now: Y

Datenbank erstellen

sudo mysql -p -u USER
CREATE DATABASE IF NOT EXISTS nextcloud;
exit

Nextcloud öffnen & konfigurieren

  • <IP-Adresse des Raspberry Pi>/nextcloud im Browser eingeben
  • Administrator-Account erstellen
  • Unten bei Speicher & Datenbank „MySQL/MariaDB“ auswählen

-> Benutzer: root, PW: vorhin festgelegt, DB-Name: nextcloud, Host: localhost

Signiertes SSL-Zertifikat installieren

Siehe Signiertes SSL-Zertifikat installieren

ddclient installieren

Siehe ddclient installieren

Daten auf externem Medium speichern

Siehe zuerst Externes Laufwerk einbinden

Als Root anmelden

sudo -s

Speicherort der Nextcloud-Daten ermitteln

nano /var/www/nextcloud/config/config.php

-> Eintrag: datadirectory (Standard: /var/www/owncloud/data)
-> Ändern in: /home/pi/usbstick

Nextcloud-Daten auf das externe Medium kopieren

cp -R /var/www/nextcloud/data/. /home/pi/usbstick

Überprüfen, ob Daten da sind

cd /home/pi/usbstick && ls -la

Datei-Eigentümer der Datenkopie ändern

chown -R www-data:www-data /home/pi/usbstick

Überprüfen, ob Eigentümer geändert wurde

ls -la

Original-Ordner nach erfolgreichem Umziehen der Daten löschen

cd /var/www/nextcloud  
rm -rf data  
exit

Anpassungen

Caches konfigurieren

sudo nano /var/www/nextcloud/config/config.php

-> Unten einfügen: 'memcache.local' => '\\OC\\Memcache\\APCu',

sudo nano /etc/php5/mods-available/opcache.ini

-> Dort hinzufügen:

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
zend_extension=opcache.so

PHP-Path Variablen

sudo nano /etc/php5/fpm/pool.d/www.conf 

Suche (CTRL+W) nach "env[HOSTNAME]"
-> Bei allen folgenden env-Variablen (HOSTNAME, PATH, TMP, TMPDIR, TEMP) das ";" entfernen

Datei-Limits anheben

sudo nano /var/www/nextcloud/.user.ini

-> Ändern:
upload_max_file_size=2048M
post_max_size=2048M

System-Cron verwenden

sudo -u www-data crontab -e

-> Dort einfügen:

*/15 * * * * php -f /var/www/nextcloud/cron.php
  • Nextcloud im Browser öffnen
  • Unter "Verwaltung" bei "Hintergrund-Aufgaben" zu "Cron" wechseln