Déploiement d'un site Drupal 10 sur un serveur Ubuntu 22.04.
L'installation de PHP entraîne l'installation de Apache :
sudo apt install php
Installation de Composer :
sudo apt install curl curl -s https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer
Les outils et extensions PHP suivantes :
sudo apt install zip unzip sudo apt install php-mbstring php-xml php-gd php-curl php-zip php-mysql
Vérifier que le module rewrite est activé :
sudo apache2ctl -M
Sinon l'activer :
sudo a2enmod rewrite sudo systemctl restart apache2
sudo vi /etc/php/8.1/apache2/php.ini
Décommenter les lignes suivantes :
extension=gd extension=mbstring extension=pdo_mysql
sudo systemctl reload apache2.service
Créer une base de données et un utilisateur ayant tous les droits sur cette base de données.
mariadb -u admin -p
Créer la base de données :
MariaDB [(none)]> create database DATABASE_NAME;
Créer un utilisateur ayant tous les droits sur cette base de données :
MariaDB [(none)]> grant all privileges on DATABASE_NAME.* TO 'USER_NAME'@'localhost' identified by 'PASSWORD';
Appliquer les privilèges :
MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit
Ne pas utiliser Composer en tant que root !
Créer le projet temporairement dans /home/marc/drupal10 :
cd /home/marc composer create-project drupal/recommended-project drupal10
Si des extensions PHP manquent, composer s'arrête et liste les extensions à installer.
Redémarrer ensuite la commande composer jusqu'à ce que tout soit installé sans erreur.
Déplacer le projet vers /var/www/drupal10 :
sudo mv /home/marc/drupal10/ /var/www
Changer le propriétaire et les droits du dossier (modifiable par le groupe) :
sudo chown -R www-data:www-data /var/www/drupal10/ sudo chmod -R 775 /var/www/drupal10/
Créer un fichier /etc/apache2/sites-available/drupal.marclebrun.be.conf
<VirtualHost *:80> ServerName drupal.marclebrun.be ServerAdmin marc@domaine.com DocumentRoot /var/www/drupal10/web <Directory /var/www/drupal10/web> Options Indexes FollowSymLinks Multiviews AllowOverride all Require all denied Require all granted Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/drupal10/error.log CustomLog ${APACHE_LOG_DIR}/drupal10/access.log combined </VirtualHost>
Créer le dossier pour les fichiers .log
sudo mkdir /var/log/apache2/drupal10 sudo chown root:adm /var/log/apache2/drupal10
Tester et activer le nouveau site :
sudo a2ensite drupal.marclebrun.be.conf sudo apachectl configtest sudo systemctl reload apache2
Ajouter un certificat let's encrypt pour le nouveau site :
sudo certbot certonly --apache
Si besoin voir Activer HTTPS avec Let's Encrypt - Ubuntu 22.04
Modifier le fichier de configuration d'Apache :
<VirtualHost *:80> ServerName drupal.marclebrun.be ServerAdmin marc@domaine.com RewriteEngine on RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} </VirtualHost> <VirtualHost *:443> ServerName drupal.marclebrun.be ServerAdmin marc@domaine.com DocumentRoot /var/www/drupal10/web <Directory /var/www/drupal10/web> Options Indexes FollowSymLinks MultiViews AllowOverride all Require all denied Require all granted allow from all </Directory> SSLEngine on SSLCertificateFile /etc/letsencrypt/live/drupal.marclebrun.be/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/drupal.marclebrun.be/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/drupal.marclebrun.be/chain.pem SSLProtocol all -SSLv2 -SSLv3 SSLHonorCipherOrder on SSLCompression off SSLOptions +StrictRequire SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" ErrorLog ${APACHE_LOG_DIR}/drupal10/error.log CustomLog ${APACHE_LOG_DIR}/drupal10/access.log combined </VirtualHost>
Re-tester et recharger la config d'Apache :
sudo apachectl configtest sudo systemctl reload apache2
Accéder à l'adresse https://drupal.marclebrun.be pour suivre les étapes d'installation de Drupal.
Éditer le fichier /sites/default/settings.php
et spécifier toutes les variante
du(des) nom(s) de domaine auxquelles le site est autorisé à répondre :
sudo chmod a+w sites/default/settings.php sudo vi sites/default/settings.php sudo chmod a-w sites/default/settings.php
$settings['trusted_host_patterns'] = [ '^marclebrun\.be$', '^.+\.marclebrun\.be$', '^marclebrun\.com$', '^.+\.marclebrun\.com$', ];