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

In this tutorial, we will configure a virtual host on Apache server.

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 “manage.chatapp.com” to run it.

Prerequisite:-

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.

httpd-vhosts.conf

STEP 3:-

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

<VirtualHost *:80>
  DocumentRoot "C:/xampp/htdocs/PROJECT_NAME"
  ServerName PROJECT_DOMAIN_URL
  <Directory "C:/xampp/htdocs/PROJECT_NAME"/>
   DirectoryIndex index.php
   AllowOverride All
   Order allow,deny
   Allow from all
 </Directory>
  ##ErrorLog "logs/dummy-host2.example.com-error.log"
  ##CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

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.

Now,

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:

WordPress.com Logo

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

Google photo

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

Twitter picture

You are commenting using your Twitter 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.

Powered by WordPress.com.

Up ↑

Create your website at WordPress.com
Get started
%d bloggers like this: