Nextcloud sur une Debian 9 Stretch Apache2 + SQLite MariaDB MySQL + certificat SSL et https

De Le Wiki du Forum-Debian.fr
Aller à la navigation Aller à la recherche
Nextcloud sur une Debian 9 Stretch Apache2 + SQLite MariaDB MySQL + certificat SSL et https
Domaine(s): Logiciels
Action(s) effectuée(s): Installation, Configuration
Paquet(s): Apache, PHP7, MariaDB, SQLite
Version debian: Stretch
Branche: Stable
Support sur lequel Debian est installé: Serveur
Niveau de difficulté: Intermédiaire
Langage(s) de programmation utilisé(s):


Dans ce tuto nous allons installer Nextcloud (un Fork de Owncloud, plus sécurisé et avec une communauté plus active) sur une Debian 9 - Stretch.

Seront abordé la question de la base de donnée (SQLite/MariaDB ou MySQL) et la question de la sécurisation avec un certificat SSL de Letsencrypt/Certbot

Prérequis

MariaDB (ou Mysql) n'est pas une dépendance obligatoire. Nextcloud peut très bien fonctionner avec SQLite sur de petites installations.

  1. Debian 9 à jour
  2. Apache2
  3. PHP 7
  4. MariaDB (N'est pas une dépendance obligatoire)

  Attention Nextcloud ne fonctionne pas - au jour ou ce tuto est écrit - avec php-7.2


# apt policy apache2 php7.0 mariadb-server

apache2:
  Installé : 2.4.25-3+deb9u3
  Candidat : 2.4.25-3+deb9u3
 Table de version :
 *** 2.4.25-3+deb9u3 500
        500 http://deb.debian.org/debian stretch/main amd64 Packages
        500 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
        100 /var/lib/dpkg/status
php7.0:
  Installé : 7.0.19-1
  Candidat : 7.0.19-1
 Table de version :
 *** 7.0.19-1 500
        500 http://deb.debian.org/debian stretch/main amd64 Packages
        100 /var/lib/dpkg/status
mariadb-server:
  Installé : 10.1.26-0+deb9u1
  Candidat : 10.1.26-0+deb9u1
 Table de version :
 *** 10.1.26-0+deb9u1 500
        500 http://deb.debian.org/debian stretch/main amd64 Packages
        500 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
        100 /var/lib/dpkg/status

Assurez-vous d'être à jour:


# apt update && apt upgrade -y && apt full-upgrade -y


# apt autoremove -y


Modules PHP

Quelques modules PHP sont nécessaires:


# apt install -y php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip


Modules Apache2 à activer

Quelques modules Apache2 sont indispensables (rewrite), certains recommandés (headers env dir mime)

# a2enmod rewrite headers env dir mime


Si votre apache tourne avec mod_fcgi activez le module setenvif:

# a2enmod setenvif


Rechargez apache:

# apachectl graceful


Récupération des sources

# cd /tmp && wget -c https://download.nextcloud.com/server/releases/nextcloud-12.0.4.zip


Récupérez le md5 et vérifiez votre téléchargement:


# wget -c https://download.nextcloud.com/server/releases/nextcloud-12.0.4.zip.md5


# md5sum -c nextcloud-12.0.4.zip.md5 < nextcloud-12.0.4.zip

nextcloud-12.0.4.zip: Réussi

Et vérifiez la signature gpg (on est jamais trop prudent...)

# wget -c https://download.nextcloud.com/server/releases/nextcloud-12.0.4.zip.asc


# wget https://nextcloud.com/nextcloud.asc && gpg --import nextcloud.asc

...
gpg: key D75899B9A724937A: public key "Nextcloud Security <security@nextcloud.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

# gpg --verify nextcloud-12.0.4.zip.asc nextcloud-12.0.4.zip

gpg: Signature made lun. 04 déc. 2017 07:24:57 UTC
gpg:                using RSA key D75899B9A724937A
gpg: Good signature from "Nextcloud Security <security@nextcloud.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 2880 6A87 8AE4 23A2 8372  792E D758 99B9 A724 937A

Puis dézippez l'archive dans un répertoire accessible par apache:

# unzip nextcloud-12.0.4.zip -d /var/www/html


Cela installera Nextcloud dans /var/www/html/nextcloud. Bien entendu c'est votre choix d'installer Nextcloud ou bon vous semble.

Si vous préférez le dossier /var/www/html/moncloud, il suffit de faire ceci:

# mv /var/www/html/nextcloud /var/www/html/moncloud


Dans ce tuto deux destinations seront traitées /var/www/html/cloud.debian-fr.xyz et /var/www/nextcloud. Répertoires qui seront accessible (une fois apache2 correctement configuré) via les url suivante: https://cloud.debian-fr.xyz et https://debian-fr.xyz/nextcloud

Donc si /var/www/nextcloud ne vous convient pas:

# mv /var/www/html/nextcloud /var/www/html/cloud.debian-fr.xyz

Les fichiers sont bien là ou je le souhaite:

# ls /var/www/html/cloud.debian-fr.xyz

3rdparty  console.php       index.html  occ           remote.php  status.php
apps      core              index.php   ocs           resources   themes
AUTHORS   cron.php          l10n        ocs-provider  robots.txt  updater
config    db_structure.xml  lib         public.php    settings    version.php

Bien évidemment les fichiers doivent appartenir à apache...


# chown -R www-data:www-data /var/www/html/cloud.debian-fr.xyz

ou

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


Configuration DNS

La configuration des DNS est inutile si vous installez Nextcloud dans le répertoire d'un domaine déjà existant (Et dont les DNS sont déjà configurés).

Afin de finir l'installation, il faudra accéder au répertoire de Nextcloud via un navigateur. Il faut donc configurer le nom de domaine chez votre registrar, comme ceci:

cloud                    IN A      37.187.253.139
cloud                    IN AAAA   2001:41d0:c:58b::1

Bien entendu, vérifiez:

# nslookup -query=A cloud.debian-fr.xyz

Server:         127.0.0.1
Address:        127.0.0.1#53

Non-authoritative answer:
Name:   cloud.debian-fr.xyz
Address: 37.187.253.139


# nslookup -query=AAAA cloud.debian-fr.xyz

Server:         127.0.0.1
Address:        127.0.0.1#53

Non-authoritative answer:
cloud.debian-fr.xyz     has AAAA address 2001:41d0:c:58b::1

Authoritative answers can be found from:
debian-fr.xyz   nameserver = dns16.ovh.net.
debian-fr.xyz   nameserver = ns16.ovh.net.

VHOST Apache2

Je considère que vous êtes (ou souhaitez être) en HTTPS. Ce n'est pas raisonnable d'installer Nextcloud en HTTP (Souvenez vous qu'en HTTP vos mots de passe circulent en clair sur Internet...) Si vous installez Nextcloud dans la racine de votre apache, je part du principe que celui-ci est déjà configuré en HTTPS.

Si vous créez un vhost, nous allons installer et configurer le certificat letsencrypt ensemble.

Nextcloud dans le répertoire racine de votre serveur apache2

Vous avez donc décompressé directement Nexcloud dans /var/www


# nano /etc/apache2/sites-available/nextcloud.conf


Alias /nextcloud "/var/www/nextcloud/"

<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

</Directory>

Activez le site

# a2ensite nextcloud

Enabling site nextcloud.
To activate the new configuration, you need to run:
  systemctl reload apache2

# systemctl reload apache2


Assurez-vous que dans la configuration du serveur apache (SSL) vous avez les lignes suivantes:

     <IfModule mod_headers.c>
          Header always set Strict-Transport-Security "max-age=15768000; preload"
     </IfModule>

Probablement dans les fichiers /etc/apache2/sites-available/default-ssl.conf ou /etc/apache2/sites-available/default.conf (en fcontion de la façon dont vous avez configuré apache2

Nextcloud à la racine d'un domaine ou sous-domaine non installé

Le certificat HTTPS

# apt install -y certbot


# nano /etc/apache2/mods-enabled/proxy.conf

<IfModule mod_proxy.c>
	ProxyPass "/.well-known/acme-challenge/" "http://127.0.0.1:9009/.well-known/acme-challenge/" retry=1
	ProxyPassReverse "/.well-known/acme-challenge/" "http://127.0.0.1:9009/.well-known/acme-challenge/"
	<Location "/.well-known/acme-challenge/">
		ProxyPreserveHost On
		Order allow,deny
		Allow from all
		Require all granted
	</Location>
</IfModule>

# a2enmod proxy proxy_http


# /etc/init.d/apache2 restart


# certbot --agree-tos --renew-by-default --standalone --preferred-challenges http-01 --http-01-port 9009 --server https://acme-v01.api.letsencrypt.org/directory certonly -d cloud.debian-fr.xyz

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Obtaining a new certificate
...
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
...

Le Vhost

# nano /etc/apache2/sites-available/cloud.debian-fr.xyz.conf


Le premier bloc <VirtualHost> sur le port 80 est pour forcer une redirection HTTPS.

Répétez les 2 blocs avec votre IPv6 (si vous avez une de configurée).

<VirtualHost 37.187.253.139:80>
     ServerAdmin THElol@debian-fr.xyz
     ServerName cloud.debian-fr.xyz

   RewriteEngine On
   RewriteCond %{HTTPS} off
   RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<IfModule mod_ssl.c>
   <VirtualHost 37.187.253.139:443>

     ServerAdmin THElol@debian-fr.xyz
     ServerName cloud.debian-fr.xyz
     DocumentRoot /var/www/cloud.debian-fr.xyz/

     <Directory /var/www/cloud.debian-fr.xyz/>
       Options +FollowSymlinks
       AllowOverride All

      <IfModule mod_dav.c>
        Dav off
      </IfModule>

       SetEnv HOME /var/www/cloud.debian-fr.xyz/
       SetEnv HTTP_HOME /var/www/cloud.debian-fr.xyz/
     </Directory>

     <IfModule mod_headers.c>
          Header always set Strict-Transport-Security "max-age=15768000; preload"
     </IfModule>

     SSLEngine on
     SSLCertificateFile /etc/letsencrypt/live/cloud.debian-fr.xyz/fullchain.pem
     SSLCertificateKeyFile /etc/letsencrypt/live/cloud.debian-fr.xyz/privkey.pem

     ErrorLog /var/log/apache2/cloud.debian-fr.xyz.error.log
     LogLevel warn
     CustomLog /var/log/apache2/cloud.debian-fr.xyz.access.log combined
     ServerSignature Off

   </VirtualHost>
</IfModule>


# a2ensite cloud.debian-fr.xyz

Enabling site cloud.debian-fr.xyz.
To activate the new configuration, you need to run:
  systemctl reload apache2

# apachectl configtest

Syntax OK

# systemctl reload apache2


Base de donnée MariaDB

Encore une fois aucune obligation d'utiliser MariaDB ou MySQL pour faire tourner Nextcloud (surtout pour une petite installation). Si vous souhaitez tout de même activer le support MariaDB, voici la procédure:


# mysql -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 29667
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
CREATE DATABASE nextcloud;
CREATE USER 'nextuser'@'localhost' IDENTIFIED BY 'hcurifezlhv';
GRANT ALL PRIVILEGES ON nextcloud . * TO 'nextuser'@'localhost';
FLUSH PRIVILEGES;
QUIT;

Installation de Nextcloud

Vous pouvez maintenant passer à l'installation à proprement parlé. En fonction de vos choix d'installation (et de votre conf apache2) rendez-vous à l'url ou se trouve votre nextcloud

  1. https://debian-fr.xyz/nextcloud
  2. https://cloud.debian-fr.xyz

1) Choisissez un couple login/mot de passe pour votre administrateur (Inutile de vous rappeler que vous devez choisir quelque chose de costaud. Et évitez admin si possible)

2) Dépliez la configuration de la base de donnée et complétez en fonction de votre choix (SQLite ou MariaDB) Laissez le répertoire par défaut pour les données:


3) Cliquez sur: Terminer l'installation. C'est tout!

Réglages divers

De belles url

Afin de ne plus avoir index.php dans vos url, modifier le fichier config et ajustez les deux variables suivantes:

'overwrite.cli.url' => 'https://cloud.debian-fr.xyz',
'htaccess.RewriteBase' => '/',

Ou en fonction de votre configuration:

'overwrite.cli.url' => 'https://debian-fr.xyz/nextcloud',
'htaccess.RewriteBase' => '/nextcloud',

Et mettez à jour le htaccess:


# sudo -u www-data php /var/www/nextcloud/occ maintenance:update:htaccess

 .htaccess has been updated

Ou


# sudo -u www-data php /var/www/cloud.debian-fr.xyz/occ maintenance:update:htaccess

.htaccess has been updated

php7.0-apcu

Installez php-apcu si ce n'est pas déjà fait:

# apt install php7.0-apcu


Modifiez la configuration dans config/config.php

'memcache.local' => '\OC\Memcache\APCu',

php7.0-opcache

Assurez-vous que php7.0-opcache est bien installé et vérifiez la configuration de Opcache dans votre php.ini


# nano /etc/php/7.0/apache2/php.ini

...
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
...


# service apache2 restart


Une dernière vérification

Au minimum, si tout est bien configuré vous devriez avoir "Tous les tests ont réussi." dans votre page d'administration

Lol (discussion) 30 décembre 2017 à 13:19 (UTC)