This article is about how to setup virtual host in xampp.
Why do you need virtual host?
Simple example is to mimic public domain in local development machine. Say you are working for a client to setup wordpress and develop theme. For that you configure and setup virtual host with client’s public domain name. This will save database action during copying your codebase from localhost to production system.
There are some steps involved to setup a virtual host:
- First check if you have installed XAMPP properly.
- Open the XAMPP control panel application and stop Apache. Be aware that late Windows machines might run it as a service, so check the box to the left of the Apache module.
- Navigate to XAMPP installation folder. Normally it is at
- Open the file named
httpd-vhosts.confwith a text editor.
- Look for
# NameVirtualHost *:80and uncomment or remove the hash.
- At the very bottom of the file paste the following code:
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
CustomLog "logs/local.undost.com-access.log" common
CustomLog "logs/localhost-access.log" common
- Next head over to your Windows host file to edit your HOSTS. the file will be located at
C:/Windows/System32/drivers/etc/hosts, where hosts is the file. Open it with notepad.
- Look forand add the following just after that line:change hosts file in windows1234# localhost name resolution is handled within DNS itself.# 127.0.0.1 localhostchange hosts file in windows to setup virtual host12345# localhost name resolution is handled within DNS itself.127.0.0.1 localhost127.0.0.1 local.undost.com #change to match your Virtual Host.
- Restart Apache and test everything.