2

I can view all files in the root directory (/var/www) but as soon as i enter a sub directory (eg /var/www/test) i get a 403 Forbidden error. I'm running Ubuntu 12.04.01.

Have tried searching for similar problems but found no solution.

Any suggestions?

Update: Checked error log in /var/log/apache2/error.log and it contains:

client denied by server configuration: /var/www/test/

Update: If i su into www-data and try to cd into any of the sub-directories it gives me the error:

cd test
sh: 4: cd: can't cd to test

Update: By doing ls -l in /var/www i get:

drwx------ 3 nicklas nicklas 4096 Sep 13 18:35 test

Could that be the issue?

Update: I fixed it! I ran the following command, and it seems to be working fine now.

cd /var/www
chown -R www-data:www-data *
3
  • 1
    Just a note, by doing that, you're giving www-data all the rights on those folders. Generally it's a good idea to give as few rights as possible to that user to limit the impact of any vulnerability in the web server or the web application it serves. So chown root:root and chmod 644 (then, www-data has read access, and only root has write access). Sep 13, 2012 at 19:48
  • Have you properly set up your sites-enabled and sites-available files?
    – terdon
    Sep 15, 2012 at 11:34
  • @qwerty You are amazing. It took me hours to find this post. Why not add your own answer and accept it? Aug 21, 2015 at 14:55

3 Answers 3

4

Check the file permissions on the sub-directories. If you have selinux enabled run the following:

restorecon -Rv /var/www
4
  • I keep hearing about selinux, but i don't think i have it enabled because i keep getting "command not found" when i run selinux commands. Can't i just run a script and set the correct permissions for all subfolders automatically?
    – qwerty
    Sep 13, 2012 at 17:01
  • @qwerty The command given, will fix all the sub-directories correctly if you have selinux. if you don't have restorecon, I think you can safely ignore that step. Sep 13, 2012 at 17:02
  • Oh okay. What do you mean by "ignore that step"? Could i install selinux and run that command to fix it? Is there another approach to fix the issue? How do i know it is permission related?
    – qwerty
    Sep 13, 2012 at 17:05
  • Please see my updated question.
    – qwerty
    Sep 13, 2012 at 17:15
3

The /var/www directory should not be owned by www-data. Not as user, and not as group.

You should chmod -R ug+rwX,o-w,o+rX /var/www.

1
0

In such case, you should always first check your error log. It should be in /var/log/apache/ or /var/log/httpd/ or something similar by default.

I'm guessing that it's caused by Indexes option which controls if someone can list files on some directory from HTTP or not. Here's some more information about it.

2
  • You're right, i checked the log and updated the question with the error message.
    – qwerty
    Sep 13, 2012 at 17:13
  • I updated the question once again, i can't seem to cd into any subdirs from www-data either.
    – qwerty
    Sep 13, 2012 at 17:15

You must log in to answer this question.

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