Solved

Setting virtual hosts for local computer

Posted on 2002-06-27
2
157 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 200 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

688 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