Virtual Host in Xampp in Windows

Apache Virtual Hosts for XAMPP in Windows

XAMPP is one of the most popular stacks for developer specially for Windows user. For developers, it’s very essential to create virtual host for their web applications or websites. I never loved Windows 10 as a developer because it’s extra complex for developer to setup environment. So I want to write this post to setup Apache virtual hosts for XAMPP.

Setup Virtual Hosts

To setup virtual hosts it’s simple. You need to write the configuration in your Apache.

After installing XAMPP, you need to go to the installation directory. Here is the example path – (remember location may differ in your PC)

C:\xampp

Then find the Apache directory. Directory name should be apache. And find configuration files.

 C:\xampp\apache\conf\extra

In the above location you will find httpd-vhosts.conf file. Open that file in your text editor. In the end of that file, here is the sample virtual host configuration you can write with your settings.

Sample Apache Virtual Hosts for XAMPP

<VirtualHost *:80>
    ServerAdmin webmaster@wordpress.local
    DocumentRoot "C:/xampp/htdocs/wordpress.local"
    ServerName wordpress.local

    <Directory "C:/xampp/htdocs/wordpress.local">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order Deny,Allow
        Allow from all
        Require all granted
    </Directory>

    # Log file location. If you want to log separately for this vhost, create the file and change the location here
    # ErrorLog "C:/xampp/htdocs/logs/wordpress.local-error.log"
    # CustomLog "C:/xampp/htdocs/logs/wordpress.local-access.log" common
</VirtualHost>

Now restart your Apache from XAMPP control panel. But you can’t access the site yet, you need to add IP for this host that you just created.

Add entry to hosts file in Windows

Go to C:\Windows\System32\drivers\etc and open hosts file in your notepad. Write the following entry in the end of that file.

127.0.0.1       wordpress.local

This is necessary because wordpress.local has no existence in the real world. So you need to tell your PC that it will look in your local loopback address for the host that you defined in your Apache and it’s running.

That’s it. Now open your browser and go http://wordpress.local, Hope this will help you.

Shaharia is a professional software engineer with more than 10 years of experience in the relevant fields. Digital ad certified, cloud platform architect, Big data enthusiasts, tech early adopters.

Site Footer