Creating VirtualHost on your local computer to start simple index.php

Share me please

When you start playing with PHP applications there is a moment when you would like to have your website to be run locally. You can build local domain for your application in some steps that I present you below.

You need to have installed xampp environment. Full instruction for xampp installation you can find in my previous post.

Hosts file configuration

Now we can start the first step. Under windows operating system you need to go to:

[code lang=”javascript” tab_size=”2″ lines=”40″]

Open file named hosts and type at the end of it the line with your local domain name, for example:


Your web browser will start looking for the entered address from the list of entered domain names in the hosts file.

Creating virtual host

When we have our local domain configured we need to define how this domain will be connected with local directory.

I like to put all my web contents in one main directory like C:/Web. Let’s create this main directory and inside it create directory that will be consumed by address. Name this folder mydomain. You should have created such path in your system:


In order to configure mapping between domain and folder we need to go to xampp configuration and to be more precise we need to configure apache serwer.

Go to the path like below and open file name httpd-vhosts.conf



In httpd-vhosts.conf file you need to uncomment the line with:

NameVirtualHost *:80

and add your configuration like below:

[code escaped=”true”]


DocumentRoot “C:\Web\mydomain”

<directory “c:\web\mydomaink” >
AllowOverride All
Require all granted



That is all. You have created connection between domain and local folder in your system.

Running your index.php file

The last step is to create simple index.php file in C:/Web/mydomain location with classic content:

[code lang=”php” ]


If you didn’t make any mistakes you can run in your web browser the address:


Leave a Reply