By default on local Windows development environment (XAMPP), users have to put all web stuff in
htdocs directory to work with many projects and experiments. For several projects (such as CMS or frameworks) it’s very useful to have separated virtual host in order to have own document root for each application.
Here are quick and easy steps to create Virtual Hosts for XAMPP.
- Navigate to
X:\, For example if XAMPP is installed in directory
C:/xamppthen navigate to
- Open the file named
httpd-vhosts.confwith a text editor.
- Uncomment the following line by removing #
- At the very bottom of the file paste the following code:
123456789101112<VirtualHost *:80>ServerAdmin webmaster@localhostDocumentRoot D:/projects/testprojectServerName testproject.dev<Directory "D:/projects/testproject">Options Indexes FollowSymLinks Includes ExecCGIAllowOverride AllOrder allow,denyAllow from all</Directory></VirtualHost>
In this snippet
testproject.devvirtual host is created and accessible by entering
http://testproject.devin browser’s address bar.
In order to create your virtual host replace
D:/projects/testprojectwith your project path. and
testproject.devwith your virtual host name.
Edit your Windows
hostsfile, located at
C:/Windows/System32/drivers/etc/directory. Open it with notepad. Open this
hostsand file could look like this:
12# localhost name resolution is handled within DNS itself.# 127.0.0.1 localhost
and add the following just after that line:123# localhost name resolution is handled within DNS itself.127.0.0.1 localhost127.0.0.1 testproject.dev #change to match your Virtual Host.
- Final Step, Restart Apache in XAMPP and test everything.