Photo de l'article

Créer un répertoires Web personnel pour chaque utilisateur sous Apache2 (LAMP)

le 19 octobre 2016

I-Contexte :

On a un serveur où ce côtoient plusieurs développeur et ou chacun d’entre eux puisse avoir sont espace web public

II-Réalisation :

ce qui est nécessaires : apache2 sur un serveur LAMP et un répertoire Home pour chacun des utilisateurs.

éditez le fichier « 000-default.conf » :

nano /etc/apache2/sites-available/000-default.conf

de base (si vous avez jamais édité votre configuration) vous arrivez sur ceci :

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request’s Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName boblecodeur.fr

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/

    # Available loglevels: trace8, …, trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with « a2disconf ».
    #Include conf-available/serve-cgi-bin.conf

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

</VirtualHost>

préparation : L’utilisateur doit créer un répertoire dans sont Home pour mettre ses fichier web.:

mkdir public_html

et vous devez activer le mode rewrite d’apache :

a2enmod rewrite

et redémarrer apache2 :

service apache2 restart

ce que nous allons faire c’est créez un allias pour chacun des utilisateurs de ce type :

lias /User /home/UserHome/public_html

exemple :

Alias /bharismendy /home/bharismendy/public_html

on indique ensuite l’emplacement des fichiers :

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted

exemple :

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted

ce qui nous donne au final :

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request’s Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName mydomain.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, …, trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with « a2disconf ».
    #Include conf-available/serve-cgi-bin.conf

    #creation des repertoires perso
    Alias /bharismendy /home/bharismendy/public_html
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
</VirtualHost>

Maintenant il faut redémarrer le serveur Web :

service apache2 restart

il aura accès a ses page web via un navigateur en entrant : nomdedomaine.tld/NomUtilisateur

ici selon l’exemple ça donne : mydomain.com/bharismendy

Il suffit de recommencer autant de fois que nécessaire.