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
- Gestion des versions de documents
- 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 LAMP5 (Linux Apache MariaDB PHP5) 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, unzip
- 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
Cette procédure d’installation de ownCloud pourrait être simplifiée en installant uniquement le paquet ownCloud mais elle pour but de mettre en évidence l’installation d’un serveur LAMP (Linux Apache MariaDB PHP) destiné à accueillir ownCloud.
1. Installation de Apache
# apt install apache2 apache2-doc
Installe les paquets suivants par dépendances :
apache2 | apache2-data | apache2-doc | apache2-utils |
2. Installation de MariaDB
# apt install mariadb-server mariadb-client
Installe les paquets suivants par dépendances :
libaio1 | libdbd-mysql-perl | libdbi-perl | libhtml-template-perl |
libmysqlclient18 | libreadline5 | libterm-readkey-perl | mariadb-client |
mariadb-client-10.0 | mariadb-client-core-10.0 | mariadb-common | mariadb-server |
mariadb-server-10.0 | mariadb-server-core-10.0 | mysql-common |
Choisir le mot de passe pour le compte d’administration de MariaDB (« root« ) et le confirmer.
3. Installation de PHP5
# apt install php5 php5-gd php5-json php5-mysql php5-curl php5-ldap php5-intl php5-mcrypt php5-imagick php5-gmp php5-imap php5-apcu php5-xmlrpc php-xml-parser
Installe les paquets suivants par dépendances :
apache2 | apache2-data | apache2-utils | libapache2-mod-php5 |
libc-client2007e | libcurl3 | libmcrypt4 | libmysqlclient18 |
libonig2 | libqdbm14 | mlock | mysql-common |
php5 | php5-apcu | php5-cli | php5-common |
php5-curl | php5-gd | php5-gmp | php5-imagick |
php5-imap | php5-intl | php5-json | php5-ldap |
php5-mcrypt | php5-mysql | php5-readline | php5-xmlrpc |
php-xml-parser | ttf-dejavu-core |
4. Installation de phpMyAdmin
# apt install phpmyadmin
Choisir le serveur web à reconfigurer automatiquement, dans notre cas apache2.
Faut-il configurer la base de données de phpmyadmin avec dbconfig-common ? Non
Nous allons le faire manuellement plus loin.
Installe les paquets suivants :
dbconfig-common | javascript-common | libjs-jquery | libjs-sphinxdoc |
libjs-underscore | libmcrypt4 | php-gettext | php-tcpdf |
php5-gd | php5-mcrypt | phpmyadmin |
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 libphp-phpmailer pdf.js-common php-assetic php-aws-sdk php-crypt-blowfish php-doctrine-annotations php-doctrine-cache php-doctrine-collections php-doctrine-common php-doctrine-dbal php-doctrine-inflector php-doctrine-lexer php-dropbox php-getid3 php-google-api-php-client php-guzzle php-opencloud php-opencloud-doc php-patchwork-utf8 php-pear php-pimple php-sabre-dav php-sabre-vobject php-seclib php-symfony-class-loader php-symfony-classloader php-symfony-console php-symfony-event-dispatcher php-symfony-eventdispatcher php-symfony-process python-ntdb python-samba python-tdb samba-common samba-common-bin smbclient vorbis-tools zendframework
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 | libphp-phpmailer | pdf.js-common |
php-assetic | php-aws-sdk | php-crypt-blowfish | php-doctrine-annotations |
php-doctrine-cache | php-doctrine-collections | php-doctrine-common | php-doctrine-dbal |
php-doctrine-inflector | php-doctrine-lexer | php-dropbox | php-getid3 |
php-google-api-php-client | php-guzzle | php-opencloud | php-opencloud-doc |
php-patchwork-utf8 | php-pear | php-pimple | php-sabre-dav |
php-sabre-vobject | php-seclib | php-symfony-class-loader | php-symfony-classloader |
php-symfony-console | php-symfony-event-dispatcher | php-symfony-eventdispatcher | php-symfony-process |
php5-oauth | python-crypto | python-ldb | python-ntdb |
python-samba | python-tdb | samba-common | samba-common-bin |
smbclient | vorbis-tools | zendframework |
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 MariaDB
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 48 Server version: 10.0.30-MariaDB-0+deb8u1 (Debian) Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS ownclouddb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> CREATE USER ocadmin@localhost IDENTIFIED BY "ocadminpw"; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON ownclouddb.* TO ocadmin@localhost; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | ownclouddb | | performance_schema | +--------------------+ 4 rows in set (0.06 sec) MariaDB [(none)]> quit; Bye
8. Configuration de Apache
Création du VirtualHost :
# nano /etc/apache2/sites-available/owncloud.conf
<VirtualHost *:80> DocumentRoot /var/www/owncloud/ ServerName owncloud.opensharing.priv Redirect permanent / https://owncloud.opensharing.priv/ </VirtualHost> <VirtualHost *:443> DocumentRoot /var/www/owncloud/ ServerName owncloud.opensharing.priv <Directory /var/www/owncloud/> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> </Directory> SetEnv HOME /var/www/owncloud SetEnv HTTP_HOME /var/www/owncloud ErrorLog /var/log/apache2/owncloud.error.log CustomLog /var/log/apache2/access.log combined SSLEngine On SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire SSLCertificateFile /etc/ssl/certs/owncloudperso.crt SSLCertificateKeyFile /etc/ssl/private/owncloudperso.key </VirtualHost>
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
Activation du VirtualHost et des modules, et vérification de la syntaxe du VirtualHost :
# a2ensite owncloud # a2enmod rewrite # a2enmod headers # a2enmod env # a2enmod dir # a2enmod mime # a2enmod ssl # apachectl configtest Syntax OK
# service apache2 restart # service mysql restart
8. 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 des dossiers owncloud et DataOwncloud :
# 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/apache2/sites-available/owncloud.conf
Ajouter les lignes suivantes dans la balise Directory :
<Directory /var/www/owncloud/> [...] <IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains" </IfModule> [...] </Directory>
# service apache2 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/.htaccess
Ci-dessous, nous définissons cette limite à 1GB.
[...] php_value upload_max_filesize 1G php_value 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.
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/ # mysqldump --user=ocadmin --password=ocadminpw --databases 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/ # mysql --user=ocadmin --password=ocadminpw 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 Apache sur Debian Jessie
- Applications pour ownCloud
- Upgrading ownCloud with the Updater App
- Importing System-wide and Personal SSL Certificates