Comment installer Grav CMS avec Nginx sur Ubuntu 20.04

Grav est un CMS gratuit, open-source et à plat qui ne nécessite aucune base de données. Il est basé sur PHP et offre plusieurs fonctionnalités qui ne sont pas forcément disponibles dans d’autres CMS comme WordPress, Joomla, etc. Il est simple, facile à utiliser et est livré avec certaines des technologies clés, notamment Twig Templating, Markdown, YAML, Parsedown, Doctrine Cache, Gregwar Image Library et Symfony Console.

Dans ce tutoriel, je vais te montrer comment installer Grav CMS avec Nginx et Let’s Encrypt SSL sur le serveur Ubuntu 20.04.

Conditions préalables

  • Un serveur fonctionnant sous Ubuntu 20.04.
  • Un nom de domaine valide pointé avec l’IP de ton serveur.
  • Un mot de passe root est configuré sur le serveur.

Démarrage

Tout d’abord, mets les paquets système à la version mise à jour en exécutant la commande suivante :

apt-get update -y

Une fois que tous les paquets sont mis à jour, tu peux passer à l’étape suivante.

Installe Nginx et PHP

Tout d’abord, tu dois installer le serveur Web Nginx, PHP et d’autres extensions PHP sur ton système. Tu peux tous les installer avec la commande suivante :

apt-get install nginx php php-cli php-fpm php-common php-curl php-gd php-json php-mbstring php-xml php-zip php-opcache php-apcu unzip -y

Une fois que tous les paquets sont installés, vérifie la version de PHP à l’aide de la commande suivante :

php --version

Tu devrais obtenir le résultat suivant :

PHP 7.4.3 (cli) (built: Jul  5 2021 15:13:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Ensuite, édite le fichier php.ini et apporte quelques modifications :

nano /etc/php/7.4/fpm/php.ini

Change les lignes suivantes :

memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
max_input_vars = 1500
date.timezone = America/Chicago

Enregistre et ferme le fichier puis redémarre le service PHP-FPM pour appliquer les modifications :

systemctl restart php7.4-fpm

Une fois que tu as terminé, tu peux passer à l’étape suivante.

Installe Grav CMS

Ensuite, tu devras télécharger le Grav CMS dans le répertoire racine du site Web de Nginx. Tu peux le télécharger depuis la page de téléchargement de Grav en utilisant la commande suivante :

cd /var/www/html
wget https://getgrav.org/download/core/grav-admin/1.7.17

Une fois le téléchargement terminé, décompresse le fichier téléchargé à l’aide de la commande suivante :

unzip 1.7.17

Ensuite, renomme le répertoire extrait en grav avec la commande suivante :

mv grav-admin grav

Ensuite, définis la propriété appropriée au répertoire grav :

chown -R www-data:www-data /var/www/html/grav

Une fois que tu as terminé, tu peux passer à l’étape suivante.

Configurer Nginx pour Grav CMS

Ensuite, tu devras créer un fichier de configuration d’hôte virtuel Nginx pour héberger Grav CMS. Tu peux le créer avec la commande suivante :

nano /etc/nginx/conf.d/grav.conf

Ajoute les lignes suivantes :

server {

listen 80;

server_name grav.example.com;
root /var/www/html/grav;

index index.html index.php;

location / {
   try_files $uri $uri/ /index.php?$query_string;
 }

   location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
   location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
   location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
   location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }

location ~ \.php$ {
   fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
 }

}

Sauvegarde et ferme le fichier lorsque tu as terminé puis vérifie que Nginx n’a pas d’erreur de syntaxe :

nginx -t

Tu devrais obtenir la sortie suivante :

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Enfin, redémarre le service Nginx pour appliquer les modifications :

systemctl restart nginx

Tu peux aussi vérifier l’état de Nginx avec la commande suivante :

systemctl status nginx

Tu devrais voir la sortie suivante :

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-07-09 06:45:28 UTC; 3s ago
       Docs: man:nginx(8)
    Process: 33099 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 33110 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 33111 (nginx)
      Tasks: 2 (limit: 2353)
     Memory: 2.6M
     CGroup: /system.slice/nginx.service
             ??33111 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??33112 nginx: worker process

Jul 09 06:45:28 node1 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 09 06:45:28 node1 systemd[1]: Started A high performance web server and a reverse proxy server.

Une fois que tout va bien, tu peux passer à l’étape suivante.

Accède à Grav CMS

Tu peux maintenant accéder à l’interface Web de Grav CMS en utilisant l’URL http://grav.example.com. Tu devrais voir l’écran suivant :

GRAV CMS

Définis ton nom d’utilisateur admin, ton mot de passe et clique sur le bouton Créer un utilisateur. Tu seras redirigé vers le tableau de bord de Grav CMS :

Tableau de bord de Grav CMS

Page de configuration

Configuration du système

Page Comptes

Comptes d'utilisateurs

Page des plugins

Plugins Grav

Page Outils

Fonction de sauvegarde

Sécurise Grav CMS avec Let’s Encrypt SSL

Ensuite, tu devras installer le paquet client Certbot pour installer et gérer le SSL Let’s Encrypt.

Tout d’abord, installe le Certbot avec la commande suivante :

apt-get install python3-certbot-nginx -y

Une fois l’installation terminée, exécute la commande suivante pour installer le SSL Let’s Encrypt sur ton site Web :

certbot --nginx -d grav.example.com

Il te sera demandé de fournir une adresse e-mail valide et d’accepter les conditions de service comme indiqué ci-dessous :

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for grav.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/grav.conf

Ensuite, choisis de rediriger ou non le trafic HTTP vers HTTPS comme indiqué ci-dessous :

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Tape 2 et appuie sur Entrée pour terminer l’installation. Tu devrais voir le résultat suivant :

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/grav.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://grav.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=grav.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/grav.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/grav.example.com/privkey.pem
   Your cert will expire on 2021-12-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Tu peux maintenant accéder au Grav CMS de manière sécurisée en utilisant le protocole HTTPS.

Conclusion

Félicitations ! Tu as installé avec succès Grav CMS avec Nginx et Let’s Encrypt SSL sur le serveur Ubuntu 20.04. Tu peux maintenant créer ton site Web facilement en utilisant le Grav CMS.

Vous aimerez aussi...