Un virtual host (ou vhost) est un mécanisme permettant de relier un nom de domaine
à un répertoire local.
Exemple: http://myproject
→ /var/www/myproject/
Déclarer un vhost : fichier /etc/apache2/sites-available/myproject.conf
<VirtualHost myproject:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/var/www/myproject"
ServerName project
<Directory "/var/www/project">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Déclarer le domaine en localhost: fichier /etc/hosts
127.0.0.1 myproject
Activer le vhost
sudo a2ensite myproject
Redémarrer Lamp
sudo service apache2 restart
Accéder à l’interface web : http://myproject
Activer les vhosts si nécessaire: C:\wamp/bin/apache/apacheX.X.X/conf/httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Déclarer un vhost : C:\wamp/bin/apache/apacheX.X.X/conf/extra/httpd-vhosts.conf
<VirtualHost myproject:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "C:/wamp/www/myproject"
ServerName myproject
<Directory "C:/wamp/www/myproject">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow, deny
Allow from all
</Directory>
</VirtualHost>
Déclarer le domaine en localhost : C:\Windows\System32\drivers\etc\hosts
127.0.0.1 myproject
Vérifier les erreurs vhost
apache2ctl = wamp\bin\apache\apacheX.X.X\bin\httpd.exe
apache2ctl -S
Redémarrer Wamp
Accéder à l’interface web : http://myproject
Ajouter un ServerAlias à la configuration du Vhost
<VirtualHost myproject:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/var/www/myproject"
ServerName myproject
+ ServerAlias *.myproject
<Directory "/var/www/myproject">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Déclarer les sous-domaines en localhost
127.0.0.1 myproject site1.myproject site2.myproject