Design a site like this with
Get started

How To Setup Virtual Host In Apache (XAMPP + PHP 5)

In this tutorial, we will setup a virtual host on Apache server. We will be using XAMPP and PHP during the process.

Virtual hosts hide the specific project name & assign a local domain to the project URL, thus locally managing the project by a domain.

For Instance:

We have project CHAT_APP at location : C:\xampp\htdocs\CHAT_APP

How do we run the project?.

We used to open http://localhost/CHAT_APP URL to run the project CHAT_APP, thus we are exposing the local server details & project details to the end-user.

After configuring virtual host,

We can directly open the project by visiting the URL say “” to run it.


We will be using XAMPP version 5.6 specifically.

If you don’t have it,just download & setup XAMPP in your machine.

Steps To Follow :-

STEP 1:-

After successfully installing XAMPP server on your machine,

Go to C:\xampp\apache\conf\extra folder

Contents of extra folder

STEP 2:-

Open httpd-vhosts.conf file.


STEP 3:-

Now, add following lines of code to the file httpd-vhosts.conf.

<VirtualHost *:80>
  DocumentRoot "C:/xampp/htdocs/PROJECT_NAME"
  <Directory "C:/xampp/htdocs/PROJECT_NAME"/>
   DirectoryIndex index.php
   AllowOverride All
   Order allow,deny
   Allow from all
  ##ErrorLog "logs/"
  ##CustomLog "logs/" common

In the above code, just replace PROJECT_NAME with the project folder name & PROJECT_DOMAIN_URL with any URL, you want to assign to your project.

Save & close the file.


STEP 4:-

Go to C:\Windows\System32\drivers\etc folder.

Contents of etc folder

STEP 5:-

Open “hosts” file in any editor.

STEP 6:-

Add the following line in the file “hosts“.

(Replace PROJECT_DOMAIN_URL with the URL that you have specified earlier).

Save & close the file.

Restart the Apache server after changes.

You are done!

You have successfully configured virtual host on Apache server. Just run the project by browsing the URL,you have specified.

Do let me know in comments, if you face difficulties with setup.

Any suggestions to improve this article are highly recommended!.

Happy Coding!.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: