Apache - Virtual Host (Vhost)


virtual host configuration with Apache

You need to restart when you change a virtual host configuration

How to set Up a Virtual Host


in the Apache Configuration file (apache/conf/httpd.conf), uncomment the line “Include conf/extra/httpd-vhosts.conf”


# Virtual hosts
Include conf/extra/httpd-vhosts.conf


Below is an example of Apache configuration, where a new virtual host is added in the httpd.conf file.

<VirtualHost *:80>
  ServerName gerardnico.local
  DocumentRoot "c:/www/"
  DirectoryIndex index.php
  <Directory "c:/www/">
    AllowOverride All
    Allow from All
  Alias /alias /alias_directory
  <Directory "/alias_directory">
    AllowOverride All
    Allow from All

In the example above, if you want that a call to gerardnico.com respond on your computer, you must change your DNS or you local Network - Hosts File. In this way, a ping will show you computer as responder.


  • servername is the FQDN with optionally the port. See doc

Farm Syntax

<VirtualHost *:8080>                     # this only works for a specific port
    ServerName gerardnico.local
    ServerAlias *.gerardnico.local       # this works for all subdomains of gerardnico.local
    DocumentRoot "f:/www/farmer"           
<VirtualHost *>                          # this works for all ports
    ServerName blog.gerardnico.local     # this only works for one specific subdomain
    DocumentRoot "f:/www/farmer"           

Suppress the comments (#) in the configuration file, they are not allowed in the xml node.


With the httpd cli, you can check the virtual host


httpd -t -D DUMP_VHOSTS
*:80                   is a NameVirtualHost
         default server localhost (C:/Apache24/conf/extra/httpd-vhosts.conf:33)
         port 80 namevhost localhost (C:/Apache24/conf/extra/httpd-vhosts.conf:33)
         port 80 namevhost doku (C:/Apache24/conf/extra/httpd-vhosts.conf:57)
*:443                  localhost (C:/Apache24/conf/extra/httpd-ahssl.conf:142)

Documentation / Reference

Powered by ComboStrap