Pour créer un premier site web avec Apache :

Prérequis :

Chez votre registrar, faire pointer votre nom de domaine vers l'adresse IP de votre serveur.


Dans le répertoire :

/var/www

créer le répertoire qui va recevoir les fichiers de votre site web.

sudo mkdir monsite.com


Autoriser l'utilisateur à accéder au répertoire :

sudo chown -R nom_utilisateur:www-data /var/www/monsite.com


Puis dans :

/etc/apache2/sites-available

Créer le fichier monsite.com.conf

sudo nano monsite.com.conf

<VirtualHost *:80>
        ServerName monsite.com
        ServerAlias monsite.com
        DocumentRoot "/var/www/monsite.com"
        <Directory "/var/www/monsite.com">
                Options +FollowSymLinks
                AllowOverride all
                Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Puis l'enregistrer :

 

sudo a2ensite monsite.com.conf

et enfin, relancer Apache :

 

sudo systemctl reload apache2


En ftp, transférer le fichier suivant :

<?php
echo "<h1>Hello !</h1>";
?>


dans

/var/www/monsite.com


Vous devriez obtenir le résultat suivent en tapant votre nom de domaine dans un navigateur :



Générer un certificat gratuit pour votre nom de domaine :

sudo certbot --apache

répondre Y puis N

Après l'opération, le fichier monsite.com-le-ssl.conf devrait ressembler à celui-ci !

<IfModule mod_ssl.c>
<VirtualHost *:443>
        Protocols h2 http/1.1
        ServerName monsite.com
        ServerAlias monsite.com
        DocumentRoot /var/www/monsite.com
        <Directory "/var/www/monsite.com">
                Options FollowSymLinks
                AllowOverride all
                Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =monsite.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/monsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/monsite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

 

Tags ubuntu