Ransford Okpoti's Dev Notes

July 21, 2008

Virtual Host Setup

Filed under: Uncategorized — Tags: — admin @ 12:26 pm

If you do not have xampp, a software bundle comprising of PHP, MySQL, FileZilla, Mercury, PEAR and other important softwares, already installed on your system, then just grab a copy from apachefriends.org and have it installed on your system.

We are going to walk through the process of setting up a virtual host on a Windows™ platform.

Let’s say you have a folder with the name mysite in your htdocs folder, for the xampp installation this is the default folder all sites are to be placed in. C:\xampp\htdocs\mysite you’ll access this site by entering http://localhost/mysite as the URL, but what if you want to access that same site using a URL like this http://www.mysite.xxx OR http://www.personalsite.xxx OR even http://www.yahoo.xxx
xxx = any extension of your choice, it could be local, dev, etc
Note: The URL you decide to use must not conflict with any publicly registered domain, for example choosing to use http://yahoo.com as a virtual host on your local server, would prevent you from accessing the real yahoo.com on the internet.

IP ADDRESS MAPPING

1. Access this folder, C:\Windows\System32\drivers\etc, on your windows platform

drivers_etc.jpg

list of files in the etc folder

2. Open the file “hosts“, which has no extension, in notepad or your favourite text editor.

3. Move to a new line in the file and add this line
127.0.0.1 www.mysite.local

4. Save and close the file

APACHE CONFIGURATION

1. Access the folder C:\xampp\apache\conf\extra and open the file, httpd-vhosts.conf, in your text editor.

2. Advance to the very end of the file and add this line if it is not already there

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>

NOTE: If your port number is other than 80, then replace all instances of port 80 with yours.

3. At the end of the file, the configuration for our new site goes in here

<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/mysite
ServerName www.mysite.local
</VirtualHost>

4. Step 3 could be repeated for the definition of a new virtual host replacing mysite with the site name.

5. Restart Apache by stopping and starting it from the xampp control.

Below is the screen cast for the post.

Powered by WordPress