Setting up virtual hosts on XAMPP* local webserver

Why create virtual hosts?

Quick step by step virtual host setup in xampp

  1. Path to your PHP project, e.g.: c:\users\username\source\mysite
  2. Path to your xampp/lampp installation, e.g.: c:\xampp
  1. Open your xampp install directory and locate httpd-vhosts.conf file under apache/conf/extra folder.
  2. Open httpd-vhosts.conf file in text editor of your choice.
  3. At the very end of the file paste the following code, but replace:
  • c:\users\username\source\mysite with actual path to your PHP project,
  • danieldusek.localhost with your own name (do yourself a favor and use actually .localhost TLD)
<VirtualHost *:80>
DocumentRoot "c:\users\username\source\mysite"
ServerName danieldusek.localhost
<Directory "c:\users\username\source\mysite">
Require all granted
</Directory>
</VirtualHost>
  1. Open c:\windows\system32\drivers\etc folder and find hosts file
  2. Open hosts file in text editor of your choice, that can save files as administrator (Visual Studio Code can elevate to Administrator in a user friendly way when saving)
  3. Add 127.0.0.1 yourdomain.localhost line at the very end of it.
  4. Save.

Step by step breakdown of what is actually going on

How it all works?

  • Told your apache server where to look for scripts when processing requests that are aimed at a specific domain that you specify in httpd-vhosts.conf.
  • Told your computer to re-route requests to yourdomain.localhost to 127.0.0.1, also known as localhost.

How does editing httpd-vhosts.conf works?

<VirtualHost *:80>
DocumentRoot "c:\users\username\source\mysite"
ServerName danieldusek.localhost
<Directory "c:\users\username\source\mysite">
Require all granted
</Directory>
</VirtualHost>

Why should you use .localhost TLD?

How does hosts file update works?

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Service-ception: how and why we’ve built a service inside a service

Meraki Home Lab Setup — Part 1

LeetCode — Rotate List

Straighten an image of a page using OpenCV

The Ultimate Guide to Get the Most Out of Your Analytics Platform

Vulnhub: Panabee1

Install ESA SNAP ToolBox along with Current Updates and Snappy Python on UBUNTU 18.04

Understanding the SOLID principles of Programming.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Daniel Dušek

Daniel Dušek

More from Medium

🔥Get to Know LaraconTZ (Virtual Event) 🔥 Speakers on April 03rd, 2022✅

How To Load Database in CodeIgniter 4 Custom Library

Top 3 Open Source CRM based on PHP [ FREE ]

How to use Monolog with a custom WordPress plugin | LAMPStack Ninja