IN ARBEIT

Installation Nextcloud

Achtung! diese Anleitung funktioniert nicht direkt bei einem Revese Proxy

Installation Basissystem

1. Installation von einem Linux System (Debian, Ubuntu)

sudo apt update
sudo apt install nano unzip zip -y
sudo apt install nginx -y

Installation php

sudo apt install php-fpm php-curl php-cli php-mysql php-gd php-common php-xml php-json php-intl php-pear php-imagick php-dev php-common php-mbstring php-zip php-soap php-bz2 php-bcmath php-gmp -y

Edit php configs

Achtung, achte bei der Version „7.4“ auf die heruntergeladene!

php -version 
sudo nano /etc/php/7.4/fpm/php.ini
sudo nano /etc/php/7.4/cli/php.ini

In den Beiden files muss folgendes geändert werden:

date.timezone = Europe/Zurich
cgi.fix_pathinfo=0
memory_limit = 512M

opcache.enable=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

Jetzt muss die php-fpm pool Config bearbeitet werden

sudo nano /etc/php/7.4/fpm/pool.d/www.conf

folgendes muss eingestellt werden:

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

pm = dynamic
pm.max_children = 120
pm.start_servers = 12
pm.min_spare_servers = 6
pm.max_spare_servers = 18
sudo systemctl restart php7.4-fpm
sudo systemctl enable php7.4-fpm

Auch hier muss wieder auf die Version geachtet werden

Datenbank

sudo apt install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation

Enter current password for root (enter for none): Press Enter
Set root password? [Y/n] N
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
mysql -u root -p

Enter password: Press Enter

CREATE DATABASE nextcloud;
CREATE USER nextclouduser@localhost IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON nextcloud.* TO nextclouduser@localhost IDENTIFIED BY 'PASSWORD';
FLUSH PRIVILEGES;
EXIT;
nano /etc/mysql/conf.d/mysql.cnf 

[mysqld]
innodb_buffer_pool_size=1G
innodb_io_capacity=4000

Nextcloud

sudo mkdir /var/www/nextcloud
cd /var/www/nextcloud

https://nextcloud.com/install/#instructions-server

Rechtsklick auf den Blauen Button → Link adresse Kopieren

sudo wget https://download.nextcloud.com/server/releases/nextcloud-19.0.1.zip

Hier darauf achten die kopierte version zu nehmen!

sudo unzip nextcloud-19.0.1.zip
sudo mv nextcloud/* ./
sudo rm nextcloud -R
cd /var/www
chown www-data:www-data nextcloud/ -R  
chmod 755 nextcloud/ -R
cd /etc/nginx/sites-available/
nano nextcloud.conf
server {
      root /var/www/nextcloud;
      index index.php index.html index.htm index.nginx-debian.html;
      server_name **domain.ch**;

      location ~ \.php$ {
              include snippets/fastcgi-php.conf;
              fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
      }

      location ~ /\.ht {
              deny all;
      }

  # Remove X-Powered-By, which is an information leak
  fastcgi_hide_header X-Powered-By;

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

  # The following 2 rules are only needed for the user_webfinger app.
  # Uncomment it if you're planning to use this app.
  #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
  #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;

  # The following rule is only needed for the Social app.
  # Uncomment it if you're planning to use this app.
  #rewrite ^/.well-known/webfinger /public.php?service=webfinger last;

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

  # set max upload size
  client_max_body_size 4096M;
  fastcgi_buffers 64 4K;

  # Enable gzip but do not remove ETag headers
  gzip on;
  gzip_vary on;
  gzip_comp_level 4;
  gzip_min_length 256;
  gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
  gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-we$;
  # Uncomment if your server is build with the ngx_pagespeed module
  # This module is currently not supported.
  #pagespeed off;

  location / {
      rewrite ^ /index.php;
  }                                                                                                                                                                                                                                        
  location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
      deny all;
  }
  location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
      deny all;
  }

  location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
      fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
      set $path_info $fastcgi_path_info;
      try_files $fastcgi_script_name =404;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $path_info;
      fastcgi_param HTTPS on;
      # Avoid sending the security headers twice
      fastcgi_param modHeadersAvailable true;
      # Enable pretty urls
      fastcgi_param front_controller_active true;
      fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
      fastcgi_intercept_errors on;
      fastcgi_request_buffering off;
  }

  location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
      try_files $uri/ =404;
      index index.php;
  }

  # Adding the cache control header for js, css and map files
  # Make sure it is BELOW the PHP block
  location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
      try_files $uri /index.php$request_uri;
      add_header Cache-Control "public, max-age=15778463";
      # Add headers to serve security related headers (It is intended to
      # have those duplicated to the ones above)
      # Before enabling Strict-Transport-Security headers please read into
      # this topic first.
      add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
      # WARNING: Only add the preload option once you read about
      # the consequences in https://hstspreload.org/. This option
      # will add the domain to a hardcoded list that is shipped
      # in all major browsers and getting removed from this list
      # could take several months.
      add_header Referrer-Policy "no-referrer" always;
      add_header X-Content-Type-Options "nosniff" always;
      add_header X-Download-Options "noopen" always;
      add_header X-Frame-Options "SAMEORIGIN" always;
      add_header X-Permitted-Cross-Domain-Policies "none" always;                                                                                                                                                                                   
      add_header X-Robots-Tag "none" always;
      add_header X-XSS-Protection "1; mode=block" always;

      # Optional: Don't log access to assets
      access_log off;
  }

  location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {                                                                                                                                                                                            
      try_files $uri /index.php$request_uri;
      # Optional: Don't log access to other assets
      access_log off;
  }
}
note: wenn dies hinter einem Reverse Proxy istalliert wird, "server_name _";

LETS ENCRYPT (SSL)

optional
sudo apt install certbot python-certbot-nginx
sudo certbot --nginx

Jetzt musst du als erstes deine Email eingeben -> (helpdesk@rafisa.ch)
danach musst di mit Y bestätigen -> Y
jetzt mit N die Mails abbestellen -> N
dann mit 2 den redirect auf https anwählen -> 2
sudo systemctl restart nginx
sudo systemctl restart php-fpm7.4-fpm

Nextcloud Konfiguration

Jetzt kann auf die Domain des Nextcloud servers Navigiert werden

Aaron Gensetter 2020/08/13 13:24