2 min read

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

Creating VirtualHost on your local computer to start simple index.php
Read aloud by your browser. Nothing is downloaded.

Part of Software Development & Tools — the development stack: environments, APIs and tooling.

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:

C:\Windows\System32\drivers\etc

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

mydomain.com

Free ebook

Free AI Video, Generated Locally

Working scripts and measured benchmarks. Free.

No spam. Unsubscribe at any time.

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 mydomain.com address. Name this folder mydomain. You should have created such path in your system:

C:/Web/mydomain

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

C:\xampp-5-6-3\apache\conf\extra

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

NameVirtualHost *:80

and add your configuration like below:

ServerName mydomain.com
 
DocumentRoot "C:\Web\mydomain"
 
<directory "c:\web\mydomaink" >
AllowOverride All
Require all granted
 
</directory>

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:

<?php
 
echo "Hello world";
 
?>

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

http://mydomain.com/index.php

Free ebook

Free AI Video, Generated Locally

Run Wan 2.1 in ComfyUI on your own GPU — the scripts I use, measured times, sample clips. No cloud, no API keys.

No spam. Unsubscribe at any time.

Did this article help?
Artur Poniedziałek
Artur Poniedziałek
IT Expert & Project Manager
🤖 AI ⚡ PM 🐍 Python 🖥️ Local AI

IT Expert & Project Manager with 15+ years of experience. Exploring practical AI applications — from local LLMs and RAG systems to workflow automation. Writing to share knowledge and inspire others to experiment with new technologies.

Leave a Reply

Your email address will not be published. Required fields are marked *