I’m going to show how I set up XAMPP so that I can use
http://myproject.test as the domain for locally developing a PHP project that is also outside the
Edit The Hosts File
First of all, we need to map the
myproject.test domain to XAMPP. Right now, if you attempt to open
http://myproject.test in the browser, it’ll attempt to resolve the domain name to an IP address via DNS and fail.
Luckily, there’s a HOSTS file that can contain pre-mapped IP-domain pairs. This means we can explicitly set that a certain domain resolves to a certain IP address. In this case, we want
myproject.test to be mapped to
127.0.0.1 , which is
localhost . From there, Apache would do the rest.
To do that, open
C:\Windows\System32\drivers\etc\hosts and make sure you open it as Administrator because it’s a system file and has higher security.
At the bottom of the file, add:
Then, save the hosts file. The changes should take effect immediately. If they don’t, try restarting your browser.
Now, if you open
http://myproject.test in your browser, you should see the XAMPP dashboard (make sure Apache is running, though).
Verify That The Vhosts File Is Loaded
Open Apache’s main configuration file,
httpd.conf . In my case, it was located at
C:/xampp/apache/conf/httpd.conf. Then, search for this:
# Virtual hosts
Make sure this
httpd-vhosts.conf file is included. We will put our virtual host configurations there.
Set Up a Virtual Host
After you’ve verified that
httpd-vhosts.conf is included, open it. Read the comments inside for some useful information and add the following block:
This is just a VirtualHost directive for the default
htdocs host behavior. We need this because as the Apache docs state:
If you are adding virtual hosts to an existing web server, you must also create a
<VirtualHost>block for the existing host.
Since we are going to add virtual hosts, our default host would go away. If you don’t need it, you also don’t need the VirtualHost directive above.
We need to add the VirtualHost directive for our project now. For this example, I’ll put my project on my Desktop at
C:/Users/USER/Desktop/test . Then, add the following to
Require all granted
The VirtualHost directive specifies the name that the server uses to identify itself and its document root. The Directory directive gives access to the root folder. Otherwise, we would receive 403 errors.
After everything is set up, add an
index.php file in your project folder and restart Apache so the virtual host configurations can be applied. Then, open
http://myproject.test and you should see your project. At the same time,
http://localhost should open the XAMPP dashboard located in
You can easily set up a nice workflow for you PHP projects by adding a custom domain to Windows’ HOSTS file and adding small configurations for Apache.
To add more projects in the same manner, repeat the same steps. Or, you can add your projects in
htdocs as always.