Virtualhosting with Apache, having more than one site on localhost - PHP / MySQL Tutorials
 
  Buy Ebooks, Video Games, DVDs, Electronics and more !
Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads Make Money Online Blog . Free Image and Photo Sharing and Hosting

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Free image hosting
   Web Design Pakistan
   Swish Templates
   SWiSH Climax
   Talkfreelance Community
   Template Desire
   Lite boards
   Script Sector
   GimpTalk
   13dots
   Idea Designs
   PHP Cafe
   Sposatoettore
   Free swishmax templates
   Swishzone

Manage your site with Flax Article Content Management System
Virtualhosting with Apache, having more than one site on localhost
Category : PHP / MySQL | Level : Beginner | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

Hi all,

Maybe as me, you develop more than one site at a time on your computer. As you have only one server (we will discuss only about apache server (either v1.3 and v2)), you should have place your site in two subdirectories and acces it through http://localhost/site1/index.html or http://localhost/site2/index.html.
I will give you a more elegant solution that will permit you to access this two site with this url
http://site1.localhost/index.html and http://site2.localhost/index.html and have their files in complety two different directories.

So go on, first of all, Stop apache server.
Then we will define our virtual host in the configuration file of apache. Default location is apache_install_dir/conf/httpd.conf.
Go at the end of this file and add the following line:

CODE
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot D:/develop/www/site1
ServerName site1.localhost
</VirtualHost>

<VirtualHost 127.0.0.1>
DocumentRoot D:/develop/www/site2
ServerName site2.localhost
</VirtualHost>


As you guess, i assume your web root directory is d:\develop\www and your site is located in subdirectory. But you could have two different place even on two different disk.
And that's all for this file. Save it and restart Apache server.

Now, we need to tell windows that when you access site2.localhost it's like you access your computer (if you don't that it will try to search on the net)..
So go edit this file c:\WINDOWS\system32\drivers\etc\hosts
and add this two line at the bottom.
CODE
127.0.0.1       site1.localhost
127.0.0.1       site2.localhost


Now, if your files are in the correct directory, you should open your favorite browser (mine is Firefox) and go to http://site1.localhost/ or http://site2.localhost/

You could add as many site as you want but don't forget each entry in the apache config file must have it's pair in the windows host file or you'll get a not found error.

Hope this help and let you work in real condition but at home. Think that you could name your server www.swish-db.com but you will not be able to come back on this forum (unless you remove the line in the hosts file).
And finally, the first virtualhost is the default one that is if you access http://localhost/ you will go to site1. (this work because 127.0.0.1 localhost is already present in the hosts file).

if you have any further question feel free to ask. If you found any bug, post it and i will modify this tut.

regards,
Sébastien

EDITED: some mispellings


© 2002-2005 Flaxweb Network | Article Manager | Gimp Tutorials Library | RAD C++ Library | Free C/C++ Sourcecode |
Sites of interest : Web Design Blog | Swish Templates | Swishmax Ebook | Photoshop Templates | Gimp Tutorials | Text Forum | Make Money Online