07/03/2018

Mettre en place un nextcloud

Nextcloud serveur (lxc container)

J’ai fait ce tuto avec la version 16.0.3 et je me suis basé su un tuto de la version 13. Donc normalement ça vaut pour pas mal de temps

Configuration du serveur

On installe MariaDB :

apt install mariadb-server

On va créer la base de données de notre Nextcloud :

Sur le CLI de myariadb , on crée notre base de données :

CREATE DATABASE nextcloud;

On va ensuite créer un user et un mot de passe pour utiliser notre base nextcloud :

GRANT ALL PRIVILEGES ON nextcloud.* TO ’user’@’localhost’ IDENTIFIED BY password’;

Lancer mariadb :

systemctl start mariadb

On installe ensuite Apache2 :

apt install apache2

Puis on installe les modules pour php :

apt install php libapache2-mod-php php-mbstring php-curl php-zip php-gd php-mysql php-bcmath php-xml php7.0-json php7.0-tidy

On active le module de réécriture apache2 (si ce n’est pas déjà fait) :

a2enmod rewrite

Puis on relance apache2 :

systemctl restart apache2

Installation de Nextcloud :

On va télécharger Nextcloud, pour cela on va ce mettre dans le dossier /var/www/html :

cd /var/www/html

Puis on télécharge la dernière version de Nextcloud sur le site : https://download.nextcloud.com/server/releases/

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

On décompresse notre fichier :

unzip nextcloud-13.0.1.zip

Puis on déplace le dossier vers /var/www/html/:

On met les droits nécessaires :

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

Configuration nginx

vim /etc/nginx/site-available/default

(On peux aussi le mettre dans un fichier à part mais là j’ai la flemme…)

upstream php-handler {
    #server 127.0.0.1:9000;
    server unix:/var/run/php/php7.3-fpm.sock;
}

server {
    listen 80;
    listen [::]:80;
    #server_name cloud.example.com;

    # Add headers to serve security related headers
    # Before enabling Strict-Transport-Security headers please read into this
    # topic first.
    #add_header Strict-Transport-Security "max-age=15768000; 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 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;
    add_header Referrer-Policy no-referrer;

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

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

    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 1G;
    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-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;

    location / {
        rewrite ^ /index.php$request_uri;
    }

    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)(\/.*|)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS off;
        # Avoid sending the security headers twice
        fastcgi_param modHeadersAvailable true;
        # Enable pretty urls
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        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=15768000; 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 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;
        add_header Referrer-Policy no-referrer;

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

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

Ou Configuration apache (buggé)

On crée notre virtual host :

touch /etc/apache2/sites-available/nextcloud.conf
ln -s /etc/apache2/sites-available/nextcloud.conf /etc/apache2/sites-enabled/nextcloud.conf
vim /etc/apache2/sites-available/nextcloud.conf

Puis on colle la configuration suivante :

<VirtualHost *:80>

ServerAdmin admin@yourdomain.com

DocumentRoot /var/www/html/nextcloud/

#ici mon met son domaine. 
ServerName your-domain.com

ServerAlias www.your-domain.com

<Directory /var/www/html/nextcloud/>

Options FollowSymLinks

AllowOverride All

Order allow,deny

allow from all

</Directory>

ErrorLog /var/log/apache2/your-domain.com-error_log

CustomLog /var/log/apache2/your-domain.com-access_log common

</VirtualHost>

On relance le serveur apache pour appliquer la nouvelle configuration :

service apache2 restart

Et après on continue de configurer sur le site

NextCloud dans un conteneur (proxy_pass)

Dans le cas où on veut l’installer dans un conteneur, il faut simplement faire une rêgle proxypass avec ngnix sur la machine hôte avec l’ip du conteneur

location ^~ /cloud/ { proxy_pass http://10.0.30.4/; }

Config du nexcloud

Ensuite il faut spécifier l’url d’entré dans le fichier de config de nexcloud.Le fichier en question est /var/www/html/nextcloud/config.php le fichier d’example est /var/www/html/nextcloud/config.sample.php

Les lignes à rajouter dans le tableau du fichier php sont

...
'overwritewebroot' => '/cloud',
'overwritehost' => 'arkalo.ovh',
'overwrite.cli.url' => 'https://arkalo.ovh/cloud',
'overwrite.cli.url' => 'https://arkalo.ovh/cloud',

...

Installer le client linux de nextcloud

vim /etc/apt/sources.list.d/nextcloud-client.list

Ajouter les ligne suivantes :

deb http://ppa.launchpad.net/nextcloud-devs/client/ubuntu zesty main 
deb-src http://ppa.launchpad.net/nextcloud-devs/client/ubuntu zesty main
apt install dirmngr
apt-key adv --recv-key --keyserver keyserver.ubuntu.com AD3DD469
apt install nextcloud-client

## Nextcloud serveur avec docker

Telecharge l’image docker

docker pull nextcloud

Lancer le container

docker run -p 80:80 nextcloud

cmd

docker run -d \
-v nextcloud:/var/www/html \
nextcloud

docker run -d \
-v db:/var/lib/mysql \
mariadb

Mise à jour

Pour mettre à jour son nextcloud, il y a 2 solutions :

A partir de cette page https://your-nextcloud.com/settings/admin/overview

Dans le repertoire de votre nextcloud, tapez cette première commande :

sudo -u www-data php updater/updater.phar

Ensuite

sudo -u www-data php occ upgrade

Ensuite sur la page https://your-nextcloud.com/settings/admin/overview vous trouverez quelque messages warning avec la documentation que vous pourrez suivre pour compléter la mise à jour.

Si on vous demande lancer une commande de ce genre occ db:add-missing-indices, il faut l’exécuter avec l’utilisateur du serveur web. Par exemple nginx c’est www-data sur Debian. La commande finale sera : sudo -u www-data php occ db:add-missing-indices

Un fois la mise à jour effectué, n’oubliez pas de mettre à jour les modules NextCloud

Sécurité

NextCloud propose un service pour tester la sécurité de votre installation. Il suffit de rentrer l’adresse de votre NextCloud ici https://scan.nextcloud.com/.