[thelist] Local apache

J.J.SOLARI jjsolari at pobox.com
Tue Jan 27 09:03:03 CST 2004

> Date: Tue, 27 Jan 2004 12:31:24 +0100
> From: Jeroen Coumans <jeroen at jeroencoumans.nl>
> To: "thelist at lists.evolt.org" <thelist at lists.evolt.org>
> Subject: [thelist] Local apache

> Message: 12
> Hi,
> I have several websites which I maintain. To simplify updates to the
> navigation, I've made all links absolute (eg. /about/ instead of
> .../../about/). To test locally, I've installed Apache. However, I'm
> having troubles figuring out how to configure it so that it works
> locally. For example, I have /var/www/website1.com and
> /var/www/website2.com.
> Is it possible to configure Apache so that it translates absolute
> links to the respective document root? I've tried aliasing, but that
> only works for one website. I've also read about virtual hosts but
> that seems to require a DNS server, and I'm a bit reluctant to
complicate my setup unless it's absolutely necessary.
> Thanks in advance,


Yes, it can be done :-)

Here's what I have done (MacOSX) for the purpose of testing different
projects locally. It is preferable to stop your Apache server first.

Locate and backup the file "httpd.conf" (usually at
/etc/httpd/httpd.conf), then just type these three lines (at end of the

    Include /private/etc/httpd/users/*.conf
    Include /private/etc/httpd/virtualhosts

The first Include references a file containing only these lines:

<Directory "/Users/nano/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all

Here, in "/Users/nano/Sites/", "nano" is the name of my account
(username), and "Sites" is the directory where all projects will reside.

The second Include references a directory which contains virtualhost
configuration files:

 - the first one, '_localhost.conf', contains these lines:

  DocumentRoot /Users/nano/Sites
  ServerName localhost
# Should you use cgi scripts, an alias to location of these
  ScriptAlias /cgi-bin /Users/nano/Sites/cgi-bin

  <Directory /Users/nano/Sites>
    Options All
    AllowOverride All

 - a second one, e.g. 'project1.conf', contains these lines:
  DocumentRoot /Users/nano/Sites/project1
  ServerName project1

  ScriptAlias /cgi-bin /Users/nano/Sites/project1/cgi-bin

  <Directory /Users/nano/Sites/project1>
    Options All
    AllowOverride All

In "Sites", create a directory named "project1" and put all files
pertaining to this project in it. Give the directory whatever name you
wish, provided that it matches the one like in the virtualhost
declaration template above.

Restart Apache, fire up your favorite browser, type <http://project1/>
and, hopefully, you are done!
Conveniently, when you do <http://localhost/>, you also get a listing of
all your different projects.

Add as many virtualhosts as you want: simply duplicate the template file
'project1.conf' in "virtualhosts" directory, and replace all occurences
of 'project1', in file name and in the file itself, by some appropriate
project name.

Finally, each new project will consist in adding a new virtualhost conf
file in "virtualshosts", and creating an appropriately named directory
containing the project itself in "Sites" (or wherever).



P.S.: I just borrowed some tips from:


More information about the thelist mailing list