?
Solved

Setting virtual hosts for local computer

Posted on 2002-06-27
2
Medium Priority
?
166 Views
Last Modified: 2013-11-18
I am a developer working on several projects.  Each of these is separate, and I'll likely have more in the future.  Each project has it's own domain and may be hosted in various places.  When I'm developing I like to have all the files on my local computer.  So I have several sub-directories, each one containing the files needed for that project.
/var/www/html/project1
/var/www/html/project2
/var/www/html/project3
etc

If I want to view the files in a browser I do something like
http://localhost/project1/afile.html
or
http://localhost/project2/thisfile.php

That is fine, except now my designer is using some include files like this
/includedfile.html

So no matter where he wants that file included (meaning on a page that may be 2 sub-directories lower than the root of the web) it will grab includedfile.html from the root directory of the web.

This works fine for each projects live domain that is hosted on a production server.
So www.project1.com/somethings/directory/testfile.html
may have the include of /includedfile.html.
includedfile.html is located at www.project1.com/includedfile.html

That all works fine, but I now need to get that same functionality locally.
If I type in localhost/somethings/directory/testfile.html I don't get the included file because apache has /var/www/html as the document root for all on the server.

What I am trying to do is set up virtual hosting for each project on my local machine.  I would like to be able to use something like http://project1.localhost and get that directory of files.  So then I can type http://project1.localhost/somethings/directory/testfile.html and the includedfile.html will be there properly because project1.localhost has the document root set at /var/www/html/project1.

Then the different project files in each sub-directory won't interfere with each other.

Is there a way to accomplish this locally and what do I alter and set up?

Mindarch
0
Comment
Question by:mindarch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
samri earned 800 total points
ID: 7113905
Mindarch,

it is possible.

What platform is your local workstation.

One possibilities is to have the www.project1.com, www.project2.com, etc. to be defined in the local hosts file.  In Unix, check the file /etc/hosts/, or if you are running Win2K (or NT) chech the file in c:\winnt\system32\drivers\etc\hosts

For example Ihad this in my c:\winnt\system32\drivers\hosts file;

127.0.0.1     www.a.com
127.0.0.1     www.b.com
127.0.0.1     www.c.com
127.0.0.1     www.d.com

Next if to configure apache to do VirtualHosting.

Apache has a great docs site for virtual hosting;


http://httpd.apache.org/docs-2.0/vhosts/
http://httpd.apache.org/docs-2.0/vhosts/examples.html

--some simple example cut and paste from that site.

Running several name-based web sites on a single IP address.

Setup:

Your server has a single IP address, and multiple aliases (CNAMES) point to this machine in DNS. You want to run a web server for www.example1.com and www.example2.org on
this machine.

      Note: Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in
      DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from
      the machine with those hosts entries.


Server configuration:

           # Ensure that Apache listens on port 80
           Listen 80

           # Listen for virtual host requests on all IP addresses
           NameVirtualHost *

           <VirtualHost *>
               DocumentRoot /www/example1
               ServerName www.example1.com

               # Other directives here

           </VirtualHost>
           
           <VirtualHost *>
               DocumentRoot /www/example2
               ServerName www.example2.org
           
               # Other directives here

           </VirtualHost>
0
 

Author Comment

by:mindarch
ID: 7187966
Thanks.  Gave me what I needed.  
0

Featured Post

Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question