HOME BLOG PORTFOLIO PHOTO CONTACT
Virtual host: Running several name-based web sites on a single IP address.

How to make 3 domain name in a single IP or machine.
Like:
1. http://moushami.com/
2. http://need11.com/
3. http://bharatbaba.com/
Before to show the code I want to show you the output in screen shot, so you can understand what exactly I want to say about this:

Screenshot1:

virtual host screen shot1

Screenshot2:

Virtual host screen shot2

 

Screenshot3:

virtual host screen shot3

 

 

Screenshot4:

screen shot virtual host4

 

Screenshot5:

virtual host screen shot 5

 

Well, so now you can understand about this:

Open this file in notepad: C:/Windows/System32/drivers/etc/hosts
Before to change any thing please keep a backup of hosts file.

Now add this line at very bottom of this file:

 

# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#    127.0.0.1       localhost
#    ::1             localhost

127.0.0.1       localhost

#127.0.0.1       zend



 
 #127.0.0.1      zend2
#127.0.0.1      zf2

#127.0.0.1       localhost

127.0.0.1       localhost
54.251.72.154 mavsocial.com

 #127.0.0.1               hotdoodle_engine.localhost localhost
 
 127.0.0.1       vhost1
 127.0.0.1       vhost2

 

Now open this file in your notepad and please keep backup before to any change:
C:wampbinapacheApache2.4.4confhttpd.conf

Now come to very bottom of this file and add below lines:

 

 

IncludeOptional "c:/wamp/vhosts/*"
Include "c:/wamp/alias/*"


# Listen for virtual host requests on all IP addresses  jay start
NameVirtualHost *:80

<VirtualHost *:80>
#DocumentRoot /www/example1  
DocumentRoot C:/wamp/www/vhost1
ServerName vhost1

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/wamp/www/vhost2


ServerName vhost2

# Other directives here

</VirtualHost>




<VirtualHost *:80>
DocumentRoot C:/wamp/www
ServerName localhost

# Other directives here

</VirtualHost>

#jay close

 

Now add 2 folder inside your localhost:

C:/wamp/www/vhost/1index1.php
C:/wamp/www/vhost2/index2.php

 

Now restart your apache server or all services

then in browser write this line:
http://vhost2/index2.php
http://vhost1/index1.php
http://localhost/

Your work is done.

Reference:
1. http://httpd.apache.org/docs/2.4/vhosts/ip-based.html
2. http://httpd.apache.org/docs/2.2/vhosts/examples.html

 

   Share on Facebook

Page views:122