Drupal est un CMS (Content Management System) Open Source sous licence GPLv2+ écrit en PHP. Il est né en 2000 et fut créé par Dries Buytaert qui le développe depuis via la société Acquia dont il est le fondateur. Sa version actuelle est la 8.3.1.
Alternatives Open Source à Drupal :
Objectif
L’objectif de cet article est l’installation et la configuration d’un serveur LAMP7 (Linux Apache MariaDB PHP7) auto-hébergé Drupal en version 8.3.1 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 Drupal | |
FQDN | drupal-test.opensharing.priv |
Adresse IP | 192.168.1.37 |
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.37 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.37 drupal-test.opensharing.priv drupal-test 192.168.1.37 drupal.opensharing.priv drupal
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 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 PHP7
Déclaration du dépôt DotDeb :
# echo "deb http://packages.dotdeb.org jessie all" > /etc/apt/sources.list.d/dotdeb.list # wget -O- https://www.dotdeb.org/dotdeb.gpg | apt-key add - # apt update
Installation de PHP7 proprement dite :
# apt install libapache2-mod-php7.0 php7.0 php7.0-apcu php7.0-bz2 php7.0-fpm php7.0-mysql php7.0-curl php7.0-json php7.0-gd php7.0-mcrypt php7.0-msgpack php7.0-memcached php7.0-intl php7.0-ldap php7.0-sqlite3 php7.0-gmp php7.0-geoip php7.0-mbstring php7.0-pgsql php7.0-xml php7.0-zip php7.0-xmlrpc php7.0-soap
Installe les paquets suivants par dépendances :
libapache2-mod-php7.0 | libapparmor1 | libcurl3 | libmcrypt4 |
libmemcached11 | libmemcachedutil2 | libpq5 | libxmlrpc-epi0 |
libzip2 | php-common | php7.0 | php7.0-apcu |
php7.0-bz2 | php7.0-cli | php7.0-common | php7.0-curl |
php7.0-phpdbg | php7.0-fpm | php7.0-gd | php7.0-geoip |
php7.0-gmp | php7.0-igbinary | php7.0-intl | php7.0-json |
php7.0-ldap | php7.0-mbstring | php7.0-mcrypt | php7.0-memcached |
php7.0-msgpack | php7.0-mysql | php7.0-opcache | php7.0-pgsql |
php7.0-readline | php7.0-soap | php7.0-sqlite3 | php7.0-xml |
php7.0-xmlrpc | php7.0-zip |
Rmq : Tous les modules installés ici ne seront pas forcément nécessaires, à commencer par ceux relatifs à PostgreSQL et SQLite.
Définir PHP7 par défaut :
# a2enmod proxy_fcgi setenvif # a2enconf php7.0-fpm
Configuration du moteur de cache Opcache permettant le stockage en mémoire des scripts PHP précompilés pour un gain de performance :
# nano /etc/php/7.0/mods-available/opcache.ini
Ajouter les lignes suivantes en fin de fichier :
opcache.memory_consumption=512 opcache.revalidate_freq=60 opcache.validate_timestamps=1 opcache.max_accelerated_files=5000
4. Installation de Drupal
# wget https://ftp.drupal.org/files/projects/drupal-8.3.1.tar.gz # tar zxvf drupal-8.3.1.tar.gz -C /var/www/ # mv /var/www/drupal-8.3.1/ /var/www/drupal/ # chown -R www-data:www-data /var/www/drupal
5. 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 drupaldb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> CREATE USER drupaladmin@localhost IDENTIFIED BY "drupaladminpw"; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON drupaldb.* TO drupaladmin@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 | +--------------------+ | drupaldb | | information_schema | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec) MariaDB [(none)]> quit; Bye
6. Configuration de Apache
# nano /etc/apache2/sites-available/drupal.conf
<VirtualHost *:80> DocumentRoot /var/www/drupal/ ServerName drupal.opensharing.priv Redirect permanent / https://drupal.opensharing.priv/ </VirtualHost> <VirtualHost *:443> DocumentRoot /var/www/drupal/ ServerName drupal.opensharing.priv <Directory /var/www/drupal/> Options +FollowSymlinks AllowOverride All </Directory> SetEnv HOME /var/www/drupal SetEnv HTTP_HOME /var/www/drupal ErrorLog /var/log/apache2/drupal.error.log CustomLog /var/log/apache2/access.log combined SSLEngine On SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire SSLCertificateFile /etc/ssl/certs/drupalperso.crt SSLCertificateKeyFile /etc/ssl/private/drupalperso.key </VirtualHost>
Génération de la clef privée :
# openssl genrsa -out /etc/ssl/private/drupalperso.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/drupalperso.key -out /etc/ssl/certs/drupalperso.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) []:drupal.opensharing.priv Email Address []:admin@opensharing.priv Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:drupalcertificate An optional company name []:OpenSharing
Construction du certificat :
# openssl x509 -req -days 365 -in /etc/ssl/certs/drupalperso.csr -signkey /etc/ssl/private/drupalperso.key -out /etc/ssl/certs/drupalperso.crt Signature ok subject=/C=FR/ST=Ile-de-France/L=Paris/O=OpenSharing/OU=Service Informatique/CN=drupal.opensharing.priv/emailAddress=admin@opensharing.priv Getting Private key
Activation du site et des modules et vérification de la syntaxe du VirtuaHost :
# a2ensite drupal # a2enmod rewrite # a2enmod ssl # apachectl configtest Syntax OK
7. Redémarrage des services
# service apache2 restart # service mysql restart # service php7.0-fpm restart
8. Configuration de Drupal par le navigateur Web
Saisir, dans la barre d’adresses, l’adresse suivante :
http://drupal.opensharing.priv
redirigeant automatiquement vers :
https://drupal.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 processus d’installation commence par le choix de la langue, puis Save and continue.
Puis vient le choix du profil d’installation, ici Standard, puis Enregistrer et continuer.
Renseigner ensuite les informations relatives à la base de données drupaldb créée précédemment.
L’installation proprement dite de Drupal se lance ensuite et prend un certain temps.
Puis vient la mise à jour des traductions, assez longue également.
Ensuite la configuration minimale du site, comme son nom et le choix d’un administrateur.
Et enfin la mise à jour de la configuration des traductions.
L’installation est terminée, la page d’accueil de Drupal s’affiche.
Le bouton Gérer donne accès aux outils de gestion et d’administration du site.
On peut maintenant créer son premier article.
Et le publier.
# nano /var/www/drupal/sites/default/settings.php
Modfier, à la ligne 713, pour éviter l’erreur suivante :
The trusted_host_patterns setting is not configured in settings.php. This can lead to security vulnerabilities. It is highly recommended that you configure this. See Protecting against HTTP HOST Header attacks for more information.
[...] **/ $settings['trusted_host_patterns'] = array( '^drupal\.opensharing\.priv
Sécurisation du dossier drupal :
# find /var/www/drupal/ -type f -print0 | xargs -0 chmod 0640 # find /var/www/drupal/ -type d -print0 | xargs -0 chmod 0750 # chown -R root:www-data /var/www/drupal/ # chown -R www-data:www-data /var/www/drupal/sites/default/files/ # service apache2 restart # service mysql restart # service php7.0-fpm restart
Pour aller plus loin
1. Effectuer une sauvegarde manuelle complète
# mkdir -p /home/adminsys/backup/8.3.1/ # cd /home/adminsys/backup/8.3.1/ # tar -czvf backup-drupal-20170423.tar.gz -C /var/www/ drupal/ # mysqldump --user=drupaladmin --password=drupaladminpw --databases drupaldb > drupal-20170423.sql
2. Effectuer une restauration manuelle complète
# cd /home/adminsys/backup/8.3.1/ # tar -xzvf backup-drupal-20170423.tar.gz -C /var/www/ # mysql --user=drupaladmin --password=drupaladminpw drupaldb < drupal-20170422.sql
Références
- Drupal – Toutes les versions en téléchargement
- Drupal – Version 8.3.1 en téléchargement
- Drupal – Installing PHP, MySQL and Apache under Linux
- Drupal – Securing file permissions and ownership
- Drupal – Clean URLs with Apache 2 on Ubuntu
, ); /** [...]
Sécurisation du dossier drupal :