Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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? I need to fix this urgently so any suggestions are very appreciated!

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 *
share|improve this question
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). –  Stephane Chazelas Sep 13 '12 at 19:48
    
Have you properly set up your sites-enabled and sites-available files? –  terdon Sep 15 '12 at 11:34
    
The "fix" = crack-able by design. Hope it's not a production system. –  Christopher Jan 12 '13 at 1:13
add comment

3 Answers

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

restorecon -Rv /var/www
share|improve this answer
    
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 '12 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. –  utopiabound Sep 13 '12 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 '12 at 17:05
    
Please see my updated question. –  qwerty Sep 13 '12 at 17:15
add comment

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.

share|improve this answer
    
You're right, i checked the log and updated the question with the error message. –  qwerty Sep 13 '12 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 '12 at 17:15
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.