Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I use root relative path for all the links in PHP files, like "url(/img/myimj.jpg)"

In Godaddy host server, that works fine.

But I want to run it in my local host. (Ubuntu 9, Apache 2, PHP 5)

For example, I have my site stored in var/www/siteone, another one stored in var/www/sitetwo,

and root directory is set to "var/www".

Now the problem is a href="/" is not linking to var/www/siteone, but var/www/.

Is there a way to define different document roots for different sites?

I am just beginner in web development, not sure if vitual host can do it.

Could someone explain it?

Thanks for your answers.

I need to add new vitualhost to this file /etc/apache2/sites-available/default

But I am still confusing, how to do it for localhost? The default IP and port is always 127.0.0.1:80

share|improve this question

migrated from stackoverflow.com Sep 10 '10 at 21:56

This question came from our site for professional and enthusiast programmers.

3 Answers 3

Each <VirtualHost> section can have its own DocumentRoot directive.

share|improve this answer

I personnally use a lot of VirtualDocumentRoot :
http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html#virtualdocumentroot

With this directive, you can do for exemple :

VirtualDocumentRoot /var/www/%-2/%-3/

%-2 is the "2nd item from the right" so it's exemple in exemple.com
%-3 is the third item from the right so it's foo in foo.exemple.com

Then you just have to make folders to match your hostnames :
localhost/ will be :

/var/www/localhost/_/

Notice the _ where there is no value (i always make a symlink like _ -> www)

So
www.site1.com will be /var/www/site1/www/
www.site2.com will be /var/www/site2/www/
localhost will be /var/www/localhost/_/

then have fun with symlinks :-)

share|improve this answer

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

There you will find examples and descriptions on solving your problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.