Design a site like this with WordPress.com
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 “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 )

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: