Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have apache2 setup on my local machine with virtualhosts.

In my hosts file, i have this: mysite

'mysite' is a site, in which i have php scripts that use include('/path/to/whatever');

If i type 'mysite' in my browser's url, everything loads fine.

If however i type http://localhost/mysite,

i get errors such as: Warning: include(/media/Shared/sites/www/includes/functions.php

Notice in the errors, after 'www', it's missing 'mysite'. so my script thinks 'www' is the root, and not 'www/mysite'. This is a problem because same thing happens when i access the site via my external IP.

How can I fix this?

share|improve this question
VirtualHost file can be seen at – sqram Sep 5 '09 at 6:33
up vote 1 down vote accepted

When you access http://localhost/mysite/, Apache will look the correct VirtualHost to use up using Apache's precendence rules, described at length in the official Apache documentation. It then depends how your different VirtualHosts are set up.

You need to have a "ServerAlias localhost" in the mysite virtual host setup otherwise Apache, most likely, will use that 000-default vhost instead. If you're running under NameVirtualHosts rules for that IP, Apache will look up the right vhost to use using the Host: header of the request, and if none match, will use the first one defined that is valid for that IP/port.

share|improve this answer

Is your "mysite" the first entry in your list of virtual hosts? If its not then accessing http://localhost/mysite/ won't be using the expected virtual host entry. Unless the hostname requested matches either the ServerName or ServerAlias entry entries in your config (wildcards are permitted) Apache won't use that entry.

share|improve this answer
That confused me. Anyhow, I am not sure if it's first on list of virtual hosts. I don't think it is as i keep my virtual hosts in the "sites-enabled" directory. In that directory, there is the 000-default vhost, which has its root set to /www – sqram Sep 5 '09 at 17:46

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.