I was messing around with virtual hosts and now I'm getting a 403 error when trying to access files on the webroot.

Here's my httpd-vhosts.conf:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www
</VirtualHost>


<VirtualHost *:80>
    ServerName test.ts
    DocumentRoot /var/www/htdocs/vhost_test 
    <Directory /var/www/htdocs/vhost_test>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

I'm pretty sure its a problem with vhosts because I commented out the line that included httpd-vhosts.conf on httpd.conf and the problem was gone. What's wrong with it?

EDIT: a day after Phil Hollenback helped me with this problem, the server began acting up again. Same problem as before, and doing what I did before didn't solve it this time. So I tried changing httpd-vhosts.conf with this:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www
    <Directory />                   #added this tag
        Allow from all
    <Directory>
</VirtualHost>

Now it's working.

link|improve this question
feedback

3 Answers

up vote 2 down vote accepted

Grep for DocumentRoot in your other conf files, like httpd.conf - is it defined anywhere outside of your vhosts? It's unclear from your question and the followups if your default DocumentRoot is actually in /var/www. You could have a different DocumentRoot pointing at an entirely different directory tree that's not /var/www - in which case changing permissions on /var/www won't affect anything.

Also when you say 'access files on the webroot' what do you mean exactly? How are you accessing the files?

link|improve this answer
Well, I looked into httpd.conf and there's a line with 'DocumentRoot "/srv/httpd/htdocs"' in it. /srv/httpd is a symbolic link to /var/www. On httpd-vhosts.conf there's a 'DocumentRoot /var/www' on the first vhost definition. I tried commenting out each one of them at a time, but no luck. I also tried to change httpd-vhosts.conf with 'DocumentRoot /var/www/htdocs' instead, but also no luck. I'm not forgetting to restart apache after every change, by the way. – David McDavidson Jan 23 '11 at 14:33
What I meant with 'access files on the webroot' is trying to open files with a browser, by typing 'localhost/somefile.html' on the address bar. – David McDavidson Jan 23 '11 at 14:34
ok so change your default DocumentRoot from /srv/httpd/htdocs to some other real directory different than /var/www, put an index.html in it, restart your apache, and see if you can then retrieve that docuemnt. – Phil Hollenback Jan 23 '11 at 19:38
It worked! I changed to /tmp/wwwtest, and it displayed index.html correctly. Now here's what's weird. I went back to httpd.conf and reverted the changes, and now the old webroot is working again! I think I'll never know what went wrong. – David McDavidson Jan 24 '11 at 0:30
Glad to help. Please accept mine or another of the answers. Also please upvote any answers which were useful. – Phil Hollenback Jan 24 '11 at 0:33
feedback

Did you do

Chown -R www-data:www-data /var/www

Make sure the user that apache is running as has permission to access /var/www

Hope that helps, RayQuang

link|improve this answer
I don't have a user or group named www-data, but I do have a user and a group named apache. I ran that command but with user and group apache, but the problem persists – David McDavidson Jan 23 '11 at 4:04
feedback

Do you have a default document defined anywhere? If that's missing or doesn't include the filename you're using as your default a 403 is often returned.

link|improve this answer
What document are you referring to? – David McDavidson Jan 23 '11 at 4:01
The file that would be returned if the requested URI was only like mysite.com instead of mysite.com/myfile.html. Apache uses the DirectoryIndex directive to define the site's list of default documents. httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex – squillman Jan 23 '11 at 4:04
I have DirectoryIndex index.html index.php on my httpd.conf, but I also get a 403 when I try to access them. – David McDavidson Jan 23 '11 at 4:23
Ok, then you should check out the permissions on your doc root and subdirectories like RayQuang mentioned in his answer. – squillman Jan 23 '11 at 4:24
I just ran chmod -R 777 /var/www . The problem is still there. This setup of mine was working before, I don't even remember messing with the configuration files before this problem arised. – David McDavidson Jan 23 '11 at 4:33
feedback

Your Answer

 
or
required, but never shown

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