shaymol Posted April 17, 2007 Share Posted April 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47429-how-to-config-virtual-host-in-localhost/ Share on other sites More sharing options...
chronister Posted April 21, 2007 Share Posted April 21, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47429-how-to-config-virtual-host-in-localhost/#findComment-234431 Share on other sites More sharing options...
shaymol Posted April 21, 2007 Author Share Posted April 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47429-how-to-config-virtual-host-in-localhost/#findComment-234562 Share on other sites More sharing options...
chronister Posted April 21, 2007 Share Posted April 21, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/47429-how-to-config-virtual-host-in-localhost/#findComment-234572 Share on other sites More sharing options...
shaymol Posted April 21, 2007 Author Share Posted April 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47429-how-to-config-virtual-host-in-localhost/#findComment-234600 Share on other sites More sharing options...
chronister Posted April 21, 2007 Share Posted April 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47429-how-to-config-virtual-host-in-localhost/#findComment-234869 Share on other sites More sharing options...
shaymol Posted April 22, 2007 Author Share Posted April 22, 2007 Hi mates Thanks a lot for your guideline . its working now Thanks again . Regards ShaymoL Quote Link to comment https://forums.phpfreaks.com/topic/47429-how-to-config-virtual-host-in-localhost/#findComment-235054 Share on other sites More sharing options...
jorgep Posted December 4, 2007 Share Posted December 4, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47429-how-to-config-virtual-host-in-localhost/#findComment-406096 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.