Setting Up Virtual Hosts For XAMPP On Windows
There are many uses for setting up virtual hosts. For example, it can neatly segregate multiple projects that are being developed concurrently. In some cases, it helps to create a development environment that is closer to production. For example, by using virtual hosts, you are able to mimic having domains and subdomains.
HOW TO SETUP
For this tutorial, we will be looking to add a virtual host with the domain name
web.devenv
. You can, of course replace this name with anything you like, but for the sake of being consistent throughout the tutorial, I will stick with
web.devenv
First, you will need to find your
hosts
file which by default on any Windows version should be at
C:\Windows\System32\drivers\etc
Second, edit the
hosts
file and add in the following lines
127.0.0.1 web.devenv
127.0.0.1 www.web.devenv
Third, find a file called
httpd-vhosts.conf
in your XAMPP directory. By default, it should be at
C:\xampp\apache\conf\extra
Fourth, edit the file and append the following to the end(or bottom) of the file. I will explain relevant fields below.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/dev/php"
ServerName web.devenv
ServerAlias www.web.devenv
ErrorLog "C:/dev/web/logs/test.dev_error_log"
CustomLog "C:/dev/web/logs/test.dev_access_log" common
<Directory "C:/dev/web">
Allow from all
Require all granted
</Directory>
</VirtualHost>
DocumentRoot is the root directory where apache will look for files. So in this case, if you would to browse to
http://web.devenv/index.php
, apache tries to look for a file at the path
C:/dev/php/index.php
.
ServerName is the domain name that you can use to access. It can be anything, even
localhost
ServerAlias is just an alias for ServerName. It can be
ww1.web.devenv
or
ww2.web.devenv
and so on
ErrorLog is the path where apache errors will be written to. The directory must exists, otherwise apache will not start. In the above example,
C:/dev/web/logs/
must exist (the file however, does not need to exist)
CustomLog is the path where custom logs will be written to. Similarly, the directory must exists, otherwise apache will not start. In the above example,
C:/dev/web/logs/
must exist (the file however, does not need to exist)
Be First to Comment