Apache 403 Forbidden on sub folders?
Solution 1
Check the file permissions on the sub-directories. If you have selinux enabled run the following:
restorecon -Rv /var/www
Solution 2
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
.
Related videos on Youtube

qwerty
Updated on September 18, 2022Comments
-
qwerty 3 months
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 *
-
Stéphane Chazelas over 10 yearsJust 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).
-
terdon over 10 yearsHave you properly set up your
sites-enabled
andsites-available
files? -
neydroydrec over 7 years@qwerty You are amazing. It took me hours to find this post. Why not add your own answer and accept it?
-
-
qwerty over 10 yearsI 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?
-
utopiabound over 10 years@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.
-
qwerty over 10 yearsOh 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 over 10 yearsYou're right, i checked the log and updated the question with the error message.
-
qwerty over 10 yearsPlease see my updated question.
-
qwerty over 10 yearsI updated the question once again, i can't seem to cd into any subdirs from www-data either.
-
ArunKumar M N almost 3 yearsperfectly worked for me