VHOSTS Guide
Posted by: bondies (122.150.201.---)
Date: February 27, 2012 05:24AM

Okay, Have seen a lot of posts about people trying to get VHOSTS running thought I would post up a quick guide to point people in the right direction.

Firstly - I am running Windows XP Pro Service Pack 3 (32 bit), and wampserver2.2c-x32

WAMP is best run as a development platform prior to a site going live on the internet, there are many security holes within the package that make it unsuitable as a live server package.

It is important to keep in mind that WAMP is simply a packaged together version of a couple of different resources commonly used to serve a web page namely - Apache (a web server), MySQL (a server based relational database management system, PHP a scripting language that can be used to link Apache & MySQL together) - hence the name WAMP (Windows, Apache, MySQL, PHP). Other packages that deliver the same software include XAMPP (the X is for Cross Platform and the extra P is for Perl). LAMP (A Linux based package). MAMP (A Mac package), and AMPPS (Apache, MySQL, PHP, PERL, Softaculous : WordPress, Drupal, Joomla!, Prestashop, Magento, phpBB, SMF, b2e, 215 scripts via Softaculous)

Virtual Hosting is used to have multiple domain names (with separate handling) on a single server or pool of servers. Virtual hosting can be name based, IP based, or port based. (See Apache Virtual Host documentation for full details - [httpd.apache.org]). I am going to focus on name based hosting for this guide.

Name based hosting uses multiple host names with the same IP address. This works by taking advantage of HTTP/1.1 - on connection to the web service the browser sends the web service the hostname and requested resource per the URL. So what we need is for the browser to know where to send the HTTP/1.1 request & for Apache to know once it receives the request where it can locate the correct resources from.

Telling the browser where to send the HTTP/1.1 request to
You have at least two options for doing this, either editing the HOSTS file or by running your own DNS server (this is outside the scope of this guide, but it is the way I do it for my network as I want my iPhones to get the right DNS settings without jail breaking them). Keep in mind you will need to edit the HOSTS file of each workstation you want to be able to access the test VHOSTS on. As this is for WAMP I will show you the Windows way to edit the HOSTS file just know though that Macs & Linux have HOSTS files also if required (further info on methods can be viewed at Corz.org [corz.org]).
There will be a hosts file & a lmhosts file (lm is for local machine)
For Windows XP,Vista,Windows 7 edit %systemroot%\system32\drivers\etc\lmhosts (%systemroot% is usually but not always C:\windows) For Windows 2000 C:\WINNT\system32\drivers\etc\lmhosts & for Windows 98/ME C:\WINDOWS\lmhosts
Add the domains you are going to setup in your VHOSTS here if it is a static IP address you can use that or if it is dynamic and the local machine use 127.0.0.1 (universal loopback address) and the name of the domain you wish to use in my example I have setup localhost, server.local,mail.local, and xbox.local (on a different IP) - so for example
127.0.0.1 localhost
127.0.0.1 server.local
127.0.0.1 mail.local
192.168.2.50 xbox.local

Save and close this file & then locate your current active httpd.conf file in my installation it is <wamp folder>\bin\apache\Apache2.2.21\conf open this file and uncomment (take the # out of the front the line) that says "# Include conf/extra/httpd-vhosts.conf" Save and close this file & locate the httpd-vhosts.conf file should be in the <wamp folder>\bin\apache\Apache2.2.21\conf\extra folder
The virtual hosts are setup in windows like this:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName server.local
ServerAlias *.local
DocumentRoot "C:/wamp/www/server"
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
ServerAdmin name@domain
DocumentRoot "C:/wamp/www/2ndserver"
DirectoryIndex index.html index.php
</VirtualHost>

Now just restart Apache & Click on the main menu of WAMP 'Put Online' should all work :-D

Options: ReplyQuote


Sorry, you can't reply to this topic. It has been closed.