Jump to content

How to Config Virtual Host in localhost


shaymol

Recommended Posts

Hi

i have installed apche2traid in my windows . so i got the apache web server with php .

it gives the default web url : http://localhost which document root is htdocs.

now i want to add multiple url under this server such as

url : http://myhost1 , document root : htdocs2

url : http://myhost2 , document root : htdocs3

 

i have tried some editing in the php.ini file in virtual host section but totally failed.

is it possible to the above things.

 

please help me

 

Thanks

Shaymol

mail : shaymol.cse@gmail.com

 

 

Link to comment
Share on other sites

I have done this in xampp and it was quite easy. In the apache config file find the line that looks like this

 

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

 

make sure to uncomment the include line and ensure your paths are correct. XAMPP gives this path and has a sample vhosts.conf file.

 

In your vhosts.conf file set it up like so with your paths and names.

 

NameVirtualHost *:80 #this line has to be there for it to work... I found out the hard way.
<VirtualHost *:80>
    DocumentRoot "c:\your\path\to\htdocs1"
    ServerName myhost1
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "c:\your\path\to\htdocs2"
    ServerName myhost2
</VirtualHost>

 

This may not be the most correct way of doing it, but it works for me in a testing environment....

 

Now I am having trouble with vhosts on an UBUNTU LAMP server.... Will start a new thread for that though.

 

I hope this helps.

Link to comment
Share on other sites

Hi mates

thanks for your idea.

but i am stiil in trouble. what i have done with httpd.conf of my local apache server is below

 

Listen 80

NameVirtualHost lamp:80

<VirtualHost lamp:80>
    ServerName lamp:80
    DocumentRoot "c:\apache2triad\LAMP"
</VirtualHost>

 

Now if i tried for http://lamp it looks up in the internet and redirect me to http://www.lamp.com/

 

I could not figure it out as why this is happening .

 

Can you please help me to resolve this problem

 

Thanks

Shaymol

Link to comment
Share on other sites

Once you have apache configured to respond to a name, you have to tell the computer how to get to that name. Open c:\windows\system32\drivers\etc\hosts in notepad and map that name to the IP. e.g.

 

127.0.0.1 localhost

127.0.0.1 lamp

 

 

you can use the loopback address of 127.0.0.1 if your accessing it from the same machine or the actual network ip address (192.168.X.X) if you want to access it from a different machine.

 

I may be wrong, but drop all the :80 chunks out of the code. I did not even need to add the Listen 80 line.

 

The example vhosts.conf I provided is exactly how I have it set up and it works perfectly for me. I had about 10-12 different sites responding. copy and paste the below chunk into vhosts.conf and modify the 2nd entry to point to the 2nd v-host you want. Then add both items into the hosts file or DNS resolve if your router has the capability and you should be golden. Remember to restart apache anytime you modify the vhosts file as it has to reload the file to pick up changes.

 

 

NameVirtualHost *:80

<VirtualHost lamp>
    ServerName lamp
    DocumentRoot "c:\apache2triad\LAMP"
</VirtualHost>

<VirtualHost site2>
    ServerName site2
    DocumentRoot "c:\apache2triad\site2"
</VirtualHost>

 

Link to comment
Share on other sites

Hi mates

Thanks again for your reply.

I have changed the hosts file that you metion as below.

 

127.0.0.1 localhost
127.0.0.1 lamp
127.0.0.1 dev

 

and in httpd.conf file i have modify with the following virtual host

 

NameVirtualHost *:80
<VirtualHost lamp>
    ServerName lamp
    DocumentRoot "c:\apache2triad\LAMP"
</VirtualHost>

<VirtualHost dev>
    ServerName dev
    DocumentRoot "c:\apache2triad\dev"
</VirtualHost>

Now its working only with lamp, that is http://localhost , http://lamp . http://dev all are accessible from the browser and all refers to document root as "c:\apache2triad\LAMP".

Why this is happening. can you please help me. 

 

Thanks

ShaymoL

Link to comment
Share on other sites

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName lamp
    DocumentRoot "c:\apache2triad\LAMP"
</VirtualHost>

<VirtualHost *:80>
    ServerName dev
    DocumentRoot "c:\apache2triad\dev"
</VirtualHost>

 

Try doing that and see if it works. I changed the name in the virtual host container from lamp, and dev to *:80. Lemme know how it goes

 

Link to comment
Share on other sites

  • 7 months later...

Once you have apache configured to respond to a name, you have to tell the computer how to get to that name. Open c:\windows\system32\drivers\etc\hosts in notepad and map that name to the IP. e.g.

 

127.0.0.1 localhost

127.0.0.1 lamp

 

you can use the loopback address of 127.0.0.1 if your accessing it from the same machine or the actual network ip address (192.168.X.X) if you want to access it from a different machine.

 

Thank you, I forgot to do this part, nobody mentions it anywhere they just talk about configuring the vhost file. Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.