AutoLogin

A CakePHP Component that will automatically login the Auth session for a duration if the user requested to (saves data to cookies).

XAMPP in Windows : Setting up vHosts

Tuesday, May 26th 2009, 1:42am
Topics: Programming, Resources
Tags: XAMPP, Windows, Vhosts
Comments: 4
Permalink - Tinylink

If you have ever used a local server, you would immediately realize that you can only develop one site at a time using the given root. You could however setup multiple folders for different websites within your local servers root, but the problem with that is they would all share the same root, big problem! To fix this you would have to set up virtual hosts, or vhosts for short. A vhost is a small server side trick (using Apache) that allows for multiple domains (websites) under the same root or IP address.

To get this working in XAMPP, we will need to edit our hosts file and the httpd-vhosts.conf file within your XAMPP setup. But before we begin, lets set up a quick example of what we will be trying to achieve. We will want to setup two websites within the htdocs folder, we will create 2 folders with the first one "site1" and the second "site2" (you can name these whatever you wish).

The first thing we need to do is open the Windows hosts with Notepad, which can be located at C:/WINDOWS/system32/drivers/etc. If you are using Windows Vista, you will need to right click on Notepad and click "Run as Administrator" to be able to open the hosts file. Once you have opened the hosts file, add the following 2 lines to the file and save it.

127.0.0.1		site1
127.0.0.1		site2


Secondly we will need to open the vhosts file located at C:/xampp/apache/conf/extra/httpd-vhosts.conf and add the following code. Copy and paste this code for each additional vhost you wish to setup.

# Uncomment the following
NameVirtualHost *:80 

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot C:/xampp/htdocs/site1
	ServerName site1

	<Directory "C:/xampp/htdocs/site1">
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot C:/xampp/htdocs/site2
	ServerName site2

	<Directory "C:/xampp/htdocs/site2">
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


Once you have completed both these tasks you must restart Apache. Once restarted, you can go to http://site1/ and all files and folders within "site1" should be displayed. You may do this for as many websites as you wish, just make sure to complete both tasks!
Related Entries:

4 Comments

10 / 2 = ?
Allowed: [code] [b] [i] [u]
  • CG
    Jun 17th 2009, 09:44
    1 One extra step needed - In httpd-vhosts.conf , find:

    #
    # Use name-based virtual hosting.
    #
    ##NameVirtualHost *:80

    uncomment the last line so it reads

    NameVirtualHost *:80
  • Renowned Media
    renownedmedia.com
    Sep 5th 2009, 12:03
    2 Nice guide. Here's a link for more detailed info on setting up xampp vhosts if anyone is interested!

    http://renownedmedia.com/blog/setting-up-vhosts-using-xampp-or-apache-in-windows/
  • sorin
    May 7th 2010, 09:04
    3 It works only for first site (whichever is first written between ). If i call the second site (those between the second ) it indicate me the first site.
    Why's that? Thank you