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
C:/xampp/apache/conf/extra
- Open the file named
httpd-vhosts.conf
with a text editor. - Look for
# NameVirtualHost *:80
and uncomment or remove the hash. - At the very bottom of the file paste the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | NameVirtualHost *:80 # # 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. # <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "C:/xampp/htdocs/undost" ServerName local.undost.com ServerAlias www.local.undost.com ErrorLog "logs/local.undost.com.log" CustomLog "logs/local.undost.com-access.log" common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "C:/xampp/htdocs" ServerName localhost ServerAlias www.local.undost.com ErrorLog "logs/localhost.log" CustomLog "logs/localhost-access.log" common </VirtualHost> |
- 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:1234# localhost name resolution is handled within DNS itself.# 127.0.0.1 localhost12345# 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.
Read more:
Secure your PHP applications with these tricks
How to set AddHandler in PHP
Follow me: @sajjadrobin
or the Beard Guy: Robin The Beard Guy (RobinTBG)
Grow 100 twitter Followers in 24 hours