Setting up Apache vhosts on Windows 7 in 3 easy steps

Posted on July 25, 2010 by Kos

Step #1:
Edit the C:\WINDOWS\system32\drivers\etc\hosts file and add:

# the name of your website
127.0.0.1    your_website_name

Step #2:
Edit the C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf file
and uncomment the following line:

#Virtual hosts
#Include conf/extra/httpd-vhosts.conf ( <-this line; around line 460)

so it should say:

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

Step #3:
Open C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf, and change:

NameVirtualHost *:80
to
NameVirtualHost *:8080

only if you have IIS7 which uses the port 80 (!), then comment default VirtualHosts (lines from ~27 to ~42) and add this:

    # The default virtual host.
    # This will allow you to access your other websites using the url like: http://localhost/8080/website/
    <VirtualHost *:8080>
    	# This is the path to your DocumentRoot. Check httpd.conf if you don't know it
        DocumentRoot E:/phproot
        ServerName localhost
        DirectoryIndex index.php
    </VirtualHost>
 
    # This is your new virtual host
    # This will enable you to call your website using a url like: http://your_website_name:8080/
    <VirtualHost *:8080>
    	# This will become the DocumentRoot path of your website
        DocumentRoot E:/phproot/your_website_name
        # The name of your website
        ServerName your_website_name
 
        <Directory "E:/phproot/your_website_name">
            Options Indexes FollowSymLinks
            DirectoryIndex index.php
            AllowOverride Options FileInfo Limit
        </Directory>
    </VirtualHost>

If you’re using an .htaccess file, make sure you don’t have this directive in it:

DirectoryIndex

or you’ll get an Internal Server Error.

Restart Apache server and your done!

Leave a Reply