Skip to content

Instantly share code, notes, and snippets.

Created March 19, 2021 17:15
Show Gist options
  • Save salahineo/996de5788a7c95947557642f0b3be00f to your computer and use it in GitHub Desktop.
Save salahineo/996de5788a7c95947557642f0b3be00f to your computer and use it in GitHub Desktop.
XAMPP Virtual Host For Windows

I’ll go step-by-step on how to create a virtual host in the XAMPP environment For Windows.

As we know, the default http://localhost points to C:\xampp\htdocs as the root directory. The desired result is to be able to visit http://examplevhost.local, with the root directory being C:\xampp\htdocs\examplevhost.

Note: The steps below are done on Windows 10, but they should also work on other Windows versions (7, 8, 8.1).

Note: I’ll assume that XAMPP is installed in C:\xampp. If it’s different on your setup, please read carefully and adjust accordingly.

Enable virtual hosts in apache configuration file

Note: This should be done only once per XAMPP installation. If you want to add another virtual host later you can skip to the next step.

  • Open this file with notepad
  • Find the line that looks like this:
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
  • Uncomment the one that starts with "Include":
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Create project files

  • Make a new folder in the htdocs with the name examplevhost
  • Add a new HTML file to this folder index.html

Add host to system hosts file

  • Open this file with notepad as administrator
  • Add this line to the bottom of the file:	examplevhost.local

Note: You should add this line localhost once in the hosts file (if it is not already exists)

Add host to XAMPP virtual hosts file

  • Open this file with notepad
  • Since we enabled this file in the first step we can start editing it. Add this:
<VirtualHost *:80>
  <Directory "C:\xampp\htdocs\examplevhost">
    AllowOverride All

  ServerName examplevhost.local
  ServerAlias www.examplevhost.local
  DocumentRoot "C:\xampp\htdocs\examplevhost"

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

Note: You can re-use this snipped for any number of virtual hosts. The directives that need changing are DocumentRoot, ServerAlias, and ServerName (ServerName must exist as an entry in C:\Windows\System32\drivers\etc\hosts).

Note: It's safe to remove the example virtual hosts that come by default.


  • Restart Apachec server from XAMPP control panel
  • Visit http://examplevhost.local and you should see the content of C:\xampp\htdocs\examplevhost\index.html.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment