Virtual Host Configuration in XAMPP

Using virtual hosts is much easier for development systems than using the default alias “project” style. Having a URL such as instead of http://localhost/example/index.php is much clearer, works better with some website “extensions” involving paths and routing, and stored passwords are much easier to manage in browsers. Let’s face it, it’s just better all around. 🙂

Follow these simple steps and you should be up and running with an easily duplicable configuration for XAMPP.

Install XAMPP & Configure Control Panel Specifics

Screen Shot of XAMP Control Panel
Add editable files here that you’ll be consistently working on when adding new domain name-based virtual hosts to your Apache configuration. Optionally, add the `hosts` file if you have the file permissions properly set so you can edit it.

Default installation should work fine. I’m running mine in Windows, so the control panel looks like this. It’s probably a good idea to add extra/httpd-vhosts.conf and extra/httpd-ssl.conf, since you’ll likely be opening those files.

Configure XAMPP

Generally, there are three (3) steps that you’ll do to configure initially, with two (2) files you’ll be constantly updating as you add new virtual domains. The line changes might be different than what’s shown here. It’s no biggie, though: Simply find the relevant line and make the necessary edits.

  • Activate Modules in httpd.conf

        LoadModule rewrite_module modules/
        LoadModule log_config_module modules/
  • Activate Virtual Host Settings in httpd.conf


    Comment out directory information:

        #DocumentRoot "E:/xampp/htdocs"
        #<Directory "E:/xampp/htdocs">

    Be sure to close the VirtualHost directive before the file includes:

        # Supplemental configuration
        # The configuration files in the conf/extra/ directory can be 
        # included to add extra features or to modify the default configuration of 
        # the server, or you may simply copy their contents here and change as 
        # necessary.
        # Server-pool management (MPM specific)
        Include conf/extra/httpd-mpm.con
  • Configure Extra Virtual Hosts Configuration File

    After making the previous changes to Apache’s base-level conf file, you can work with the vhost extra conf file.

        <VirtualHost *:80>
            DocumentRoot "C:\Users\JHaas\Documents\Projects\MyExampleSite"
            ErrorLog "logs/"
            CustomLog "logs/" common
                Options Indexes FollowSymLinks
            AllowOverride all
            Order Deny,Allow
            Deny from all
            Allow from
            DirectoryIndex index.html index.php
  • Editing /etc/hosts

    Finally, you edit the /etc/hosts file. This file is helps your system bypass the need for a DNS query, allowing you to create your own TLD (top-level domain) suffix such as *.dev, or anything that isn’t going to collide with current new top-level domain suffixes (*.me used to be quite popular until that suffix itself became a TLD suffix).

    The localhost entry is not required, and from my experience has actually caused problems if uncommented, so leave it commented out if it is already. If you see that localhost is not commented out (depending on your platform), be sure to leave it so. Changing the localhost entry from default can cause issues for many network services if it’s changed. Note that chrome has an issue with using *.local, so it’s probably best to avoid using this TLD suffix.   localhost
Notify of
Inline Feedbacks
View all comments