ownCloud est un cloud Open Source sous licence AGPLv3 permettant notamment le stockage et le partage de fichiers en ligne. Il a été crée en 2010 par Frank Karlitschek dans le cadre du projet KDE et sa version actuelle est la 9.1.4. Son créateur a depuis créé un fork de ownCloud appelé Nextcloud.
Il offre de nombreuses fonctionnalités, potentiellement étendues grâce à des applications officielles ou non, dont :
- Partage de fichiers par lien public
- Synchronisation avec clients Android/iPhone ou Windows/Linux/MAC OS X
- Sécurisation des partages par mot de passe ou date d’expiration des liens
- Authentification et partage par un annuaire LDAP
- Edition de texte en ligne et visionnage de PDF et documents Open Office
- Galeries photos
- Lecture de musiques ou de vidéos en streaming
- Quotas de stockage
- Suivi de l’activité et notifications par mail
- Calendrier (avec synchronisation CalDAV), annuaire de contacts (avec synchronisation CarDAV) et gestionnaire de taches
- etc.
Alternatives Open Source à ownCloud :
Objectif
L’objectif de cet article est l’installation et la configuration d’un serveur LEPP7 (Linux Nginx PostgreSQL PHP7) auto-hébergé ownCloud en version 9.1.4 sur une distribution Linux Debian Jessie 8.7 32bits.
Schéma logique

Pré-requis
1. Pré-requis avant réalisation
- Un serveur Debian Jessie 8.7 32 bits fonctionnel (installation basique avec utilitaires usuels du système et service SSH)
- Packages de base supplémentaires : sudo, resolvconf, tree
- Domaine utilisé : opensharing.priv
2. Configuration réseau initiale
Serveur ownCloud | |
FQDN | owncloud-test.opensharing.priv |
Adresse IP | 192.168.1.20 |
Réseau | 192.168.1.0/24 |
Passerelle | 192.168.1.1 |
dns-nameservers | 192.168.1.11 192.168.1.12 |
dns-search | opensharing.priv |
Contenu initial du fichier /etc/network/interfaces :
auto lo iface lo inet loopback allow-hotplug eth0 iface eth0 inet static address 192.168.1.20 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-search opensharing.priv dns-nameservers 192.168.1.11 192.168.1.12
Contenu initial du fichier /etc/hosts :
127.0.0.1 localhost.localdomain localhost 192.168.1.20 owncloud-test.opensharing.priv owncloud-test 192.168.1.20 owncloud.opensharing.priv owncloud
Rmq : L’adresse 127.0.1.1 doit être retirée sur un serveur à IP fixe et remplacée par cette dernière, tel que l’exemple ci-dessus.
Contenu initial du fichier /etc/host.conf :
order hosts, bind multi on
Contenu initial du fichier /etc/resolv.conf :
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 192.168.1.11 nameserver 192.168.1.12 search opensharing.priv
Rmq :
Le fichier /etc/resolv.conf ne doit pas être édité dès lors que le paquet resolvconf a été installé.
Pour prendre en compte les modifications des fichiers de configuration relatifs au réseau, redémarrage du service réseau :
# /etc/init.d/networking restart # /etc/init.d/networking reload
Réalisation
1. Installation de Nginx
# wget -O - http://nginx.org/keys/nginx_signing.key | apt-key add - # nano /etc/apt/sources.list.d/nginx.list
deb http://nginx.org/packages/debian/ jessie nginx deb-src http://nginx.org/packages/debian/ jessie nginx
# apt update # apt install nginx
Installe uniquement le paquet nginx, aucune dépendance ne lui est liée.
2. Installation de PostgreSQL
# apt install postgresql libpq-dev
Installe les paquets suivants par dépendances :
comerr-dev | krb5-multidev | libgssrpc4 | libkadm5clnt-mit9 |
libkadm5srv-mit9 | libkdb5-7 libpq-dev | libpq-dev | libpq5 |
libssl-dev | libssl-doc | postgresql | postgresql-9.4 |
postgresql-client-9.4 | postgresql-client-common | postgresql-common | zlib1g-dev |
3. Installation de PHP7
# wget -O- https://www.dotdeb.org/dotdeb.gpg | apt-key add - # nano /etc/apt/sources.list.d/dotdeb.list
deb http://packages.dotdeb.org jessie all deb-src http://packages.dotdeb.org jessie all
# apt update # apt install php7.0 php7.0-fpm php7.0-curl php7.0-gd php7.0-mcrypt php7.0-msgpack php7.0-memcached php7.0-intl php7.0-gmp php7.0-geoip php7.0-mbstring php7.0-xml php7.0-zip php7.0-imap php7.0-xmlrpc php7.0-pgsql php7.0-ldap php7.0-apcu php7.0-imagick
Installe les paquets suivants par dépendances :
libapparmor1 | libc-client2007e | libcurl3 | libmcrypt4 |
libmemcached11 | libmemcachedutil2 | libxmlrpc-epi0 | libzip2 |
mlock | php-common | php7.0 | php7.0-apcu |
php7.0-cli | php7.0-common | php7.0-curl | php7.0-fpm |
php7.0-gd | php7.0-geoip | php7.0-gmp | php7.0-igbinary |
php7.0-imagick | php7.0-imap | php7.0-intl | php7.0-json |
php7.0-ldap | php7.0-mbstring | php7.0-mcrypt | php7.0-memcached |
php7.0-msgpack | php7.0-opcache | php7.0-pgsql | php7.0-readline |
php7.0-xml | php7.0-xmlrpc | php7.0-zip |
libwxbase3.0-0 | libwxgtk3.0-0 | pgadmin3 | pgadmin3-data |
pgagent |
5. Installation des paquets supplémentaires (optionnels)
# apt install fonts-font-awesome fonts-linuxlibertine fonts-lohit-deva fonts-wqy-microhei javascript-common libjs-chosen libjs-dojo-core libjs-dojo-dijit libjs-dojo-dojox libjs-jcrop libjs-jquery libjs-jquery-metadata libjs-jquery-minicolors libjs-jquery-mousewheel libjs-jquery-tablesorter libjs-jquery-timepicker libjs-jquery-ui libjs-mediaelement libjs-pdf libjs-sphinxdoc libjs-twitter-bootstrap libjs-underscore pdf.js-common python-ntdb python-samba python-tdb samba-common samba-common-bin smbclient vorbis-tools
Installe les paquets suivants par dépendances :
fonts-font-awesome | fonts-linuxlibertine | fonts-lohit-deva | fonts-wqy-microhei |
javascript-common | libjs-chosen | libjs-dojo-core | libjs-dojo-dijit |
libjs-dojo-dojox | libjs-jcrop | libjs-jquery | libjs-jquery-metadata |
libjs-jquery-minicolors | libjs-jquery-mousewheel | libjs-jquery-tablesorter | libjs-jquery-timepicker |
libjs-jquery-ui | libjs-mediaelement | libjs-pdf | libjs-sphinxdoc |
libjs-twitter-bootstrap | libjs-underscore | pdf.js-common | python-crypto |
python-ldb | python-ntdb | python-samba | python-tdb |
samba-common | samba-common-bin | smbclient | vorbis-tools |
6. Installation de ownCloud
# wget https://download.owncloud.org/community/owncloud-9.1.4.zip # unzip owncloud-9.1.4.zip -d /var/www/ # chown -R www-data:www-data /var/www/owncloud/ # adduser --system owncloud # mkdir /home/owncloud/DataOwncloud # chown www-data:www-data /home/owncloud/DataOwncloud # chmod 750 /home/owncloud/DataOwncloud/
7. Configuration de PostgreSQL
# su postgres $ psql psql (9.4.10) Saisissez « help » pour l'aide. postgres=# CREATE ROLE ocadmin ; CREATE ROLE postgres=# ALTER ROLE ocadmin WITH PASSWORD 'ocadminpw' ; ALTER ROLE postgres=# ALTER ROLE ocadmin WITH LOGIN ; ALTER ROLE postgres=# CREATE DATABASE ownclouddb ; CREATE DATABASE postgres=# ALTER DATABASE ownclouddb OWNER TO ocadmin ; ALTER DATABASE postgres=# \list Liste des bases de données Nom | Propriétaire | Encodage | Collationnement | Type caract. | Droits d'accès ------------+--------------+----------+-----------------+--------------+----------------------- ownclouddb | ocadmin | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | postgres | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | template0 | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (4 lignes) postgres=# \q $ exit #
8. Configuration de Nginx
# nano /etc/nginx/conf.d/owncloud.conf
upstream php-handler { server unix:/run/php/php7.0-fpm.sock; } server { listen 80; server_name owncloud.opensharing.priv; # enforce https return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name owncloud.opensharing.priv; ssl_certificate /etc/ssl/certs/owncloudperso.crt; ssl_certificate_key /etc/ssl/private/owncloudperso.key; # Add headers to serve security related headers 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; # Path to the root of your installation root /var/www/owncloud/; # set max upload size client_max_body_size 10G; fastcgi_buffers 64 4K; # Disable gzip to avoid the removal of the ETag header gzip off; # Uncomment if your server is build with the ngx_pagespeed module # This module is currently not supported. #pagespeed off; index index.php; error_page 403 /core/templates/403.php; error_page 404 /core/templates/404.php; rewrite ^/.well-known/carddav /remote.php/dav/ permanent; rewrite ^/.well-known/caldav /remote.php/dav/ permanent; # 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; location = /robots.txt { allow all; log_not_found off; access_log off; } location ~ ^/(build|tests|config|lib|3rdparty|templates|data)/ { deny all; } location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; } location / { rewrite ^/remote/(.*) /remote.php last; rewrite ^(/core/doc/[^\/]+/)$ $1/index.html; try_files $uri $uri/ =404; } location ~ \.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 on; fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice fastcgi_pass php-handler; fastcgi_intercept_errors on; } # Adding the cache control header for js and css files # Make sure it is BELOW the location ~ \.php(?:$|/) { block location ~* \.(?:css|js)$ { add_header Cache-Control "public, max-age=7200"; # Add headers to serve security related headers 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; # Optional: Don't log access to assets access_log off; } # Optional: Don't log access to other assets location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ { access_log off; } }
Génération de la clef privée :
# openssl genrsa -out /etc/ssl/private/owncloudperso.key 1024
Generating RSA private key, 1024 bit long modulus
..++++++
.................++++++
e is 65537 (0x10001)
Demande de certificat à partir de la clef :
# openssl req -new -key /etc/ssl/private/owncloudperso.key -out /etc/ssl/certs/owncloudperso.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank. For some fields there will be a default value, if you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:FR State or Province Name (full name) [Some-State]:Ile-de-France Locality Name (eg, city) []:Paris Organization Name (eg, company) [Internet Widgits Pty Ltd]:OpenSharing Organizational Unit Name (eg, section) []:Service Informatique Common Name (e.g. server FQDN or YOUR name) []:owncloud.opensharing.priv Email Address []:admin@opensharing.priv Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:occertificate An optional company name []:OpenSharing
Construction du certificat :
# openssl x509 -req -days 365 -in /etc/ssl/certs/owncloudperso.csr -signkey /etc/ssl/private/owncloudperso.key -out /etc/ssl/certs/owncloudperso.crt Signature ok subject=/C=FR/ST=Ile-de-France/L=Paris/O=OpenSharing/OU=Service Informatique/CN=owncloud.opensharing.priv/emailAddress=admin@opensharing.priv Getting Private key
Vérification de la syntaxe de la configuration de Nginx :
# nginx -tc /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
9. Configuration de PHP7
# nano -c /etc/php/7.0/fpm/pool.d/www.conf
Modifier les 2 lignes suivantes (lignes 47 et 48) :
[...] listen.owner = nginx listen.group = nginx [...]
Et décommenter la suivante (ligne 385) :
[...] env[PATH] = /usr/local/bin:/usr/bin:/bin [...]
# nano /etc/php/7.0/mods-available/opcache.ini
Ajouter les lignes suivantes :
[...] opcache.memory_consumption=512 opcache.revalidate_freq=60 opcache.validate_timestamps=1 opcache.max_accelerated_files=5000
10. Redémarrage des services
# service postgresql restart # service nginx restart # service php7.0-fpm restart
11. Configuration de ownCloud par le navigateur Web
Saisir, dans la barre d’adresses, l’adresse suivante :
http://ownCloud.opensharing.priv
redirigeant automatiquement vers :
https://owncloud.opensharing.priv/
Le répondeur OCSP nous signifie que le certificat n’émane pas d’une autorité de certification reconnue, un message d’avertissement est donc émis.
Cliquer sur Avancé puis Ajouter une exception…
Il suffit ensuite de Confirmer l’exception de sécurité.
Le portail d’authentification de ownCloud s’affiche. Choisir un identifiant pour l’administrateur ainsi qu’un mot de passe, et définir le lieu de stockage des données des utilisateurs. Nous l’avons plus haut défini dans /home/owncloud/DataOwncloud. En aucun cas, le répertoire utilisé ne doit se situer dans /var/www/owncloud.
Plus bas, renseigner les informations relatives à la base de données ownclouddb définies lors de la configuration de MariaDB.
Cliquer ensuite sur Terminer l’installation. Si tout va bien, le cloud de l’administrateur s’affiche.
Sécurisation du dossier owncloud :
# usermod nginx -aG www-data # find /var/www/owncloud/ -type f -print0 | xargs -0 chmod 0640 # find /var/www/owncloud/ -type d -print0 | xargs -0 chmod 0750 # chown -R root:www-data /var/www/owncloud/ # chown -R www-data:www-data /var/www/owncloud/apps/ # chown -R www-data:www-data /var/www/owncloud/config/ # chown -R www-data:www-data /var/www/owncloud/themes/
Pour aller plus loin
1. Debugging
Sans certaines modifications, certains messages d’erreur ou informatifs apparaitront sur l’interface d’administration.
1.1. Message d’erreur relatif à l’en-tête HTTP
Message observé :
L’en-tête HTTP « Strict-Transport-Security » n’est pas configurée à « 15552000 » secondes.
Correctif :
# nano /etc/nginx/conf.d/owncloud.conf
Ajouter la ligne suivantes dans les deux sections relatives aux headers :
[...] # Add headers to serve security related headers add_header Strict-Transport-Security "max-age=15552000; includeSubDomains; preload;"; [...]
# service nginx restart
1.2. Message informatif relatif au cache mémoire
Message observé :
Aucun cache de la mémoire n’est configuré. Si possible, configurez un « memcache » pour augmenter les performances.
Correctif :
# nano /var/www/owncloud/config/config.php
Ajouter la ligne suivante :
<?php $CONFIG = array ( ... 'memcache.local' => '\\OC\\Memcache\\APCu', ... );
Après ces modifications, l’interface d’administration devrait être clean.
1.3. Modifier la taille des fichiers uploadables
Par défaut, la taille des fichiers uploadables est limitée à 513MB.
Cette taille peut être modifiée en éditant le fichier /var/www/owncloud/.user.ini
Ci-dessous, nous définissons cette limite à 1GB.
[...] upload_max_filesize=1G post_max_size=1G [...]
Dans tous les cas, cette limite ne peut excéder 2 GB car le système d’exploitation sur lequel est installé ownCloud est en 32 bits. Pour des tailles potentielles supérieures des fichiers uploadables, il faut se tourner vers un OS 64 bits.
Rmq : Avec Nginx, contrairement à Apache, le fichier .htaccess n’est pas utilisé.
2. Effectuer une sauvegarde manuelle complète
# mkdir -p /home/adminsys/backup/9.1.4/ # cd /home/adminsys/backup/9.1.4/ # tar -czvf backup-owncloud-20170409.tar.gz -C /var/www/ owncloud/ # tar -czvf backup-dataowncloud-20170409.tar.gz -C /home/owncloud/ DataOwncloud/ # PGPASSWORD="ocadminpw" pg_dump -U ocadmin -h localhost -d ownclouddb > owncloud-20170409.sql
3. Effectuer une restauration manuelle complète
# cd /home/adminsys/backup/9.1.4/ # tar -xzvf backup-owncloud-20170409.tar.gz -C /var/www/ # tar -xzvf backup-dataowncloud-20170409.tar.gz -C /home/owncloud/ # PGPASSWORD="ocadminpw" psql -U ocadmin -h localhost -d ownclouddb < owncloud-20170409.sql
4. Effectuer un upgrade de version
# chown -R www-data:www-data /var/www/owncloud/ # sudo -u www-data php /var/www/owncloud/occ upgrade
ou
# chown -R www-data:www-data /var/www/owncloud/ # sudo -u www-data php /var/www/owncloud/updater/application.php ownCloud updater 1.0 - CLI based ownCloud server upgrades Checking system health. - file permissions are ok. Current version is 9.1.4.2 Online version is 9.1.5 [stable] What would you do next? [0] download [1] upgrade [2] abort > 1 Downloaded 100% (40025874 of 40025874) Created checkpoint 9.1.4.2-5907b2a1dd566 simulated (optionally, can be done online in advance) real [danger, might take long] Disable app calendar: [success] Extracting source into /home/owncloud/DataOwncloud/updater-data/_oc_upgrade/9.1.5 Copying the application activity Copying the application comments Copying the application configreport Copying the application dav Copying the application encryption Copying the application external Copying the application federatedfilesharing Copying the application federation Copying the application files Copying the application files_antivirus Copying the application files_external Copying the application files_pdfviewer Copying the application files_sharing Copying the application files_texteditor Copying the application files_trashbin Copying the application files_versions Copying the application files_videoplayer Copying the application firstrunwizard Copying the application gallery Copying the application notifications Copying the application provisioning_api Copying the application systemtags Copying the application templateeditor Copying the application updatenotification Copying the application user_external Copying the application user_ldap Set log level to debug Turned on maintenance mode Checking whether the database schema can be updated (this can take a long time depending on the database size) Checked database schema update Checking updates of apps Checked database schema update for apps Updating database schema Updated database Drop old database tables Remove old (< 9.0) calendar/contact shares Fix permissions so avatars can be stored again Starting code integrity check... Finished code integrity check Update successful Turned off maintenance mode Reset log level Enable app calendar: [success] Done Done # find /var/www/owncloud/ -type f -print0 | xargs -0 chmod 0640 # find /var/www/owncloud/ -type d -print0 | xargs -0 chmod 0750 # chown -R root:www-data /var/www/owncloud/ # chown -R www-data:www-data /var/www/owncloud/apps/ # chown -R www-data:www-data /var/www/owncloud/config/ # chown -R www-data:www-data /var/www/owncloud/themes/
Si le mode maintenance est actif, le désactiver :
# sudo -u www-data php /var/www/owncloud/occ maintenance:mode --off
Maintenance mode disabled
Redémarrage du navigateur potentiellement nécessaire.
5. Créer un checkpoint
# sudo -u www-data php /var/www/owncloud/updater/application.php upgrade:checkpoint --create
Created checkpoint 9.1.5.2-5907b4fc6e073
6. Lister les checkpoints
# sudo -u www-data php /var/www/owncloud/updater/application.php upgrade:checkpoint --list
9.1.4.2-5907b2a1dd566 - May 02 2017 00:12
9.1.5.2-5907b4fc6e073 - May 02 2017 00:21
6. Restaurer un checkpoint
# chown -R www-data:www-data /var/www/owncloud/ # sudo -u www-data php /var/www/owncloud/updater/application.php upgrade:checkpoint --restore=9.1.4.2-5907b2a1dd566 Restored checkpoint 9.1.4.2-5907b2a1dd566 # find /var/www/owncloud/ -type f -print0 | xargs -0 chmod 0640 # find /var/www/owncloud/ -type d -print0 | xargs -0 chmod 0750 # chown -R root:www-data /var/www/owncloud/ # chown -R www-data:www-data /var/www/owncloud/apps/ # chown -R www-data:www-data /var/www/owncloud/config/ # chown -R www-data:www-data /var/www/owncloud/themes/
7. Lister les certificats SSL importés
# sudo -u www-data php /var/www/owncloud/occ security:certificates +-------------------+---------------------------+--------------+-------------+---------------------------+ | File Name | Common Name | Organization | Valid Until | Issued By | +-------------------+---------------------------+--------------+-------------+---------------------------+ | owncloudperso.crt | owncloud.opensharing.priv | OpenSharing | May 1, 2018 | owncloud.opensharing.priv | +-------------------+---------------------------+--------------+-------------+---------------------------+
8. Importer un certificat SSL
# sudo -u www-data php /var/www/owncloud/occ security:certificates:import /etc/ssl/certs/owncloudperso.crt
9. Supprimer un certificat SSL importé
# sudo -u www-data php /var/www/owncloud/occ security:certificates:remove owncloudperso.crt
Références
- Manuel d’administration du serveur ownCloud 9.1
- Manuel d’administration du serveur ownCloud 9.1 – Avertissements sur la page d’administration
- Certbot – Installation pour Nginx sur Debian Jessie
- ComputersnYou – How To Install Owncloud 9 Server with NGINX and PostgreSQL on Ubuntu
- Angristan – Installer PHP 7 sous Debian 8 Jessie via le dépôt Dotdeb
- linode – How to Configure nginx
- PHP – opcache configuration
- Nginx.org – Nginx configuration
- Applications pour ownCloud
- Upgrading ownCloud with the Updater App
- Importing System-wide and Personal SSL Certificates