Apache - Virtual Host (Vhost)

Card Puncher Data Processing


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

Discover More
Card Puncher Data Processing
(Apache|Oracle HTTP Server|Oracle Web Cache) (httpd)

Apache is a web server. The executable is httpd. This section regroups some article such as: a manual installation on Windows with php How to add virtual host or rewrite URL to configuration...
Card Puncher Data Processing
Apache - Gateway (Reverse Proxy)

in Apache A reverse proxy is activated using: the ProxyPass directive or the [P] flag to the RewriteRule directive. It is not necessary to turn ProxyRequests on in order to configure a reverse...
Card Puncher Data Processing
Apache - HTTP Header (mod_header module)

mod_header is a apache module that permits to set HTTP header. If you add the below code snippet in your htaccess file, you will set the following response header the cache-control header and...
Card Puncher Data Processing
Apache - Installation of a Private Key and Certificate (mod_ssl)

mod_ssl A private key and a certificate. For a self signed certificate, see When Apache with mod_ssl is installed, it creates several directories in the Apache config directory. Copy the...
Card Puncher Data Processing
Apache - URL Rewrite (mod_rewrite)

URL rewrite in Apache is done through the rewrite module. The rules are set in the htaccess file This module operates on the full URLs (including the path-info part) both: in per-server context (httpd.conf)...
Php Home Path System User
Installation of Apache on Windows 10 with Apache Lounge

This article shows you how easy it is to install apache on Windows 10
Nginx - Server Block Definition

A server block is a block that define a web server endpoints. It maps an URI to: a local directory or an other URI () and set some configurations. It is the equivalent of a Virtual host for apache....
Ovh Virtual Hosting Subdomain
What is and how works a virtual host / custom domain / vanity hostnames

This article gives you an overview on how and where virtual hosting / custom domain is implemented.

Share this page:
Follow us:
Task Runner