Installation Laravel · 9 min read · Nov 01, 2025

Comment installer le framework PHP Laravel avec Nginx et le SSL gratuit Let's Encrypt sur AlmaLinux 8

Laravel est un framework web PHP gratuit, open-source et léger utilisé pour construire des applications web basées sur PHP. Il est populaire en raison de sa syntaxe élégante, de ses fonctionnalités avancées et de son ensemble d’outils robuste. Il est basé sur le framework Symfony et aide les développeurs à simplifier le développement d’applications web. Il fournit également une interface en ligne de commande Artisan pour effectuer des opérations pour vos applications. Il offre des fonctionnalités puissantes, notamment Artisan, l’architecture MVC, la cartographie objet-relationnelle, le moteur de templates, les tests unitaires et le système de migration de base de données.

Dans cet article, nous allons vous montrer comment installer Laravel avec Nginx sur Alma Linux 8.

Prérequis

  • Un serveur exécutant Alma Linux 8.
  • Un nom de domaine valide pointé vers l’IP de votre serveur.
  • Un mot de passe root configuré sur votre serveur.

Installer le serveur LEMP

Tout d’abord, vous devrez installer Nginx, MariaDB, PHP et d’autres extensions PHP requises sur votre serveur. Vous pouvez tous les installer en exécutant la commande suivante :

dnf install nginx mariadb-server php php-fpm php-common php-xml php-mbstring php-json php-zip php-mysqlnd curl unzip -y

Après avoir installé tous les paquets, éditez le fichier de configuration php-fpm et configurez-le pour utiliser Nginx :

nano /etc/php-fpm.d/www.conf

Changez les lignes suivantes :

listen.owner = nginx
listen.group = nginx

Enregistrez et fermez le fichier, puis éditez le fichier de configuration PHP et changez les valeurs par défaut :

nano /etc/php.ini

Changez les lignes suivantes :

date.timezone = Asia/Kolkata
cgi.fix_pathinfo=1

Enregistrez et fermez le fichier, puis démarrez et activez les services Nginx, MariaDB et PHP-FPM en utilisant la commande suivante :

systemctl start nginx  
systemctl start mariadb  
systemctl start php-fpm  
systemctl enable nginx  
systemctl enable mariadb  
systemctl enable php-fpm

Une fois que vous avez terminé, vous pouvez passer à l’étape suivante.

Installer Composer

Dans cet article, nous allons installer Laravel en utilisant Composer. Vous devrez donc installer Composer sur votre système. Vous pouvez l’installer en exécutant la commande suivante :

curl -sS https://getcomposer.org/installer | php

Vous obtiendrez la sortie suivante :

All settings correct for using Composer
Downloading...

Composer (version 2.2.3) successfully installed to: /root/composer.phar
Use it: php composer.phar

Ensuite, déplacez le binaire Composer vers le chemin système et définissez les permissions appropriées avec la commande suivante :

mv composer.phar /usr/local/bin/composer  
chmod +x /usr/local/bin/composer

Ensuite, vérifiez la version de Composer avec la commande suivante :

composer --version

Vous obtiendrez la sortie suivante :

Composer version 2.2.3 2021-12-31 12:18:53

Installer Laravel sur Alma Linux 8

Ensuite, changez le répertoire vers le répertoire racine web Nginx et installez Laravel en utilisant Composer :

cd /var/www/html/  
composer create-project --prefer-dist laravel/laravel laravel

Vous obtiendrez la sortie suivante :

Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
69 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan key:generate --ansi
Application key set successfully.

Ensuite, définissez la propriété et les permissions appropriées pour Laravel :

chown -R nginx:nginx /var/www/html/laravel/  
chown -R nginx:nginx /var/www/html/laravel/storage/  
chown -R nginx:nginx /var/www/html/laravel/bootstrap/cache/  
chmod -R 0777 /var/www/html/laravel/storage/  
chmod -R 0775 /var/www/html/laravel/bootstrap/cache/

Une fois que vous avez terminé, vous pouvez passer à l’étape suivante.

Créer un hôte virtuel Nginx pour Laravel

Ensuite, vous devrez créer un fichier de configuration Nginx pour Laravel. Vous pouvez le créer en utilisant la commande suivante :

nano /etc/nginx/conf.d/laravel.conf

Ajoutez les lignes suivantes :

server {
       listen 80;
       server_name laravel.exampledomain.com;
       root        /var/www/html/laravel/public;
       index       index.php;
       charset utf-8;
       gzip on;
    gzip_types text/css application/javascript text/javascript application/x-javascript  image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
        location / {
         try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php {
                include fastcgi.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php-fpm/www.sock;
        }
        location ~ \.ht {
                deny all;
        }
}

Enregistrez et fermez le fichier, puis vérifiez la configuration de Laravel pour toute erreur :

ginx -t

Vous devriez 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

Ensuite, redémarrez les services Nginx et PHP-FPM pour appliquer les modifications :

systemctl restart php-fpm  
systemctl restart nginx

Vous pouvez également vérifier l’état de Nginx en utilisant la commande suivante :

systemctl status nginx

Vous obtiendrez la sortie suivante :

? nginx.service - Le serveur HTTP et proxy inverse nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
           ??php-fpm.conf
   Active: active (running) since Fri 2022-01-07 08:29:11 UTC; 4s ago
  Process: 8186 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 8184 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 8182 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 8188 (nginx)
    Tasks: 2 (limit: 11411)
   Memory: 3.7M
   CGroup: /system.slice/nginx.service
           ??8188 nginx: master process /usr/sbin/nginx
           ??8189 nginx: worker process

Jan 07 08:29:11 linux systemd[1]: nginx.service: Succeeded.
Jan 07 08:29:11 linux systemd[1]: Stopped Le serveur HTTP et proxy inverse nginx.
Jan 07 08:29:11 linux systemd[1]: Starting Le serveur HTTP et proxy inverse nginx...
Jan 07 08:29:11 linux nginx[8184]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 07 08:29:11 linux nginx[8184]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 07 08:29:11 linux systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jan 07 08:29:11 linux systemd[1]: Started Le serveur HTTP et proxy inverse nginx.

Configurer le pare-feu pour Laravel

Ensuite, vous devrez autoriser les ports 80 et 443 à travers le pare-feu firewalld. Vous pouvez les autoriser avec la commande suivante :

firewall-cmd --zone=public --permanent --add-service=http  
firewall-cmd --zone=public --permanent --add-service=https

Ensuite, rechargez le firewalld pour appliquer les modifications :

firewall-cmd --reload

Accéder à l’interface web de Laravel

Maintenant, ouvrez votre navigateur web et accédez à l’interface web de Laravel en utilisant l’URL http://laravel.exampledomain.com. Vous devriez voir la page par défaut de Laravel sur l’écran suivant :

Laravel

Activer SSL sur le site web Laravel

Il est recommandé d’activer le SSL sur le site web Laravel pour sécuriser la connexion. Let’s Encrypt fournit un SSL gratuit pour obtenir, renouveler et gérer des certificats SSL/TLS pour votre domaine. Tout d’abord, installez le client Certbot avec la commande suivante :

dnf install epel-release -y  
dnf install certbot -y

Ensuite, exécutez la commande suivante pour télécharger le SSL Let’s Encrypt pour votre domaine Laravel :

certbot --nginx -d laravel.exampledomain.com

On vous demandera de fournir votre email 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 laravel.exampledomain.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/laravel.conf

Ensuite, sélectionnez si vous souhaitez ou non rediriger le trafic HTTP vers HTTPS :

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

Tapez 2 et appuyez sur Entrée pour commencer le processus. Une fois le certificat installé, vous devriez voir la sortie suivante :

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://laravel.exampledomain.com

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/laravel.exampledomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/laravel.exampledomain.com/privkey.pem
   Your cert will expire on 2022-04-11. 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.

À ce stade, votre site web Laravel est sécurisé avec le SSL Let’s Encrypt. Vous pouvez maintenant y accéder en toute sécurité en utilisant l’URL https://laravel.exampledomain.com.

Conclusion

Félicitations ! Vous avez réussi à installer Laravel avec Nginx et le SSL Let’s Encrypt sur Alma Linux 8. Vous pouvez maintenant commencer à développer des applications basées sur PHP en utilisant le framework Laravel. N’hésitez pas à me poser des questions si vous en avez.

Share: X/Twitter LinkedIn

Recevez de nouveaux articles dans votre boîte de réception.

Aucun spam. Désabonnez-vous à tout moment.