PDA

View Full Version : Apache 2.0: Virtual DocumentRoot


duesi
07-27-06, 07:13 AM
Hi all,

I have a test server with apache 2.0. Now I want to put several projects into subdirectories of its DocumentRoot, but for them, it should "feel" as if they are in the document root.

So for example:
(My document root is /srv/www/htdocs/).

In /srv/www/htdocs/project1 I have file which references "/inc". This should refer to /srv/www/htdocs/project1/inc and not to /srv/www/htdocs/inc, which is the default.

I do not want to build Virtual Hosts if it is not needed (I do not have a Network Card for each project :-)

Is there any easy way to do this?

Thanks for your advice!

koncept
07-27-06, 08:07 AM
you can set up host headers and only use one nic. (i am not sure if host headers are equivalent to virtual hosts) if thye are then you will need to set them up if you want all the sites to be available at any given time

duesi
07-28-06, 06:27 AM
koncept, thanks for pointing me in the right direction.
Here is what I did:

- I added a CNAME for our dev-server in our local DNS (/var/lib/named/local.zone):


project1 IN CNAME dev-server


- then I wrote a new virtual-host file and put it in /etc/apache2/vhosts.d/


<VirtualHost *>

ServerName project1.local

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot /srv/www/htdocs/project1

# don't loose time with IP address lookups
HostnameLookups Off

# needed for named virtual hosts
UseCanonicalName Off

Include /etc/apache2/conf.d/*.conf

<Directory "/srv/www/htdocs/project1">
DirectoryIndex index.html
AllowOverride All
Options All
Order allow,deny
Allow from all
</Directory>

#PHP stuff
php_admin_value safe_mode 0
php_admin_value file_uploads 1

</VirtualHost>



Note that my settings are pretty lax, it's a development machine!

I noticed that when I did an relative include in PHP, it would not work because it works relative to the "main"-document root.
So I had to change


<?php include("/inc/top_header.shtml"); ?>


into


<?php include($_SERVER['DOCUMENT_ROOT']."/inc/top_header.shtml"); ?>


Happy Coding!