0

I have apache2 setup on my local machine with virtualhosts.

In my hosts file, i have this:

127.0.1.1 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?

1

2 Answers 2

1

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.

0

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.

1
  • 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, 2009 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .