Post-Image

Create dynamic virtual hosts on XAMPP with Windows

Posted on

This is a short tutorial how the get up and running with dynamic virtual hosts with XAMPP on Windows. The goal of this tutorial is to be able to create a directory like “local.mywebsite.com” in your C:\xampp\htdocs\ to add a virtual host dynamically.

First of we have to install XAMPP if you haven’t already. Please install it into the default folder C:\xampp because this will save us some typing later on.

After the XAMPP installation is finished we have to activate the vhost module in Apache. To do this you have to open the file C:\xampp\apache\conf\httpd.conf and remove the # at the beginning of this line.



LoadModule vhost_alias_module modules/mod_vhost_alias.so


Next paste the following snippet into your C:\xampp\apache\conf\extra\httpd-vhosts.conf file.

<VirtualHost *:80>
    UseCanonicalName Off
    ServerAlias *
    VirtualDocumentRoot "C:/xampp/htdocs/%0"
    VirtualScriptAlias "C:/xampp/htdocs/%0"
    LogLevel debug
    <Directory "C:/xampp/htdocs/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order Allow,Deny
        Allow from all
        Require local
    </Directory>
</VirtualHost>

And that’s it. Now we just have to test it out. To see error when starting apache it’s best not to start it with the XAMPP panel but to start it by executing the  C:\xampp\apache_start.bat script. The script will show you if there are any problems with your configuration when starting apache.

If you run into problems at this point leave a comment with your error message and I’ll try to help you. (Except if you’ve installed your XAMPP into the programs folder, in this case I can’t help you any longer.)

When there aren’t any problems you can start Apache from now on with the XAMPP panel. If you now want to add a host you can just create the folder in your C:\xampp\htdocs\ folder and add a entry to your C:\Windows\system32\drivers\etc\hosts file. (To edit this file open your text editor first with admin rights.)



127.0.0.1 beta.eggworks.ch


Now you’re all setup. If you have any comments, proposals or ideas how to improve this article feel free to comment below.

4 thoughts on “Create dynamic virtual hosts on XAMPP with Windows

    1. This depends on your other vhost setup. It is possible to configure this setup to only map certain tld’s into the directory.

      You’d have to try it out yourself and then tell me if there is any error.

Leave a Reply