9

I feel like this is a fairly simple fix and have seen similar problems when searching but haven't been able to fix it with those solutions. Basically the problem is I cannot access any subdirectories on my webserver. Going to localhost brings up the index fine. But going to localhost/test gives a 403 Forbidden error.

I'm running CentOS. I've tried editing the /etc/httpd/conf/httpd.conf file a couple of ways but have had no luck. The DocumentRoot is located at /var/www/html. Currently I have:

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

I've tried adding the following:

<Directory "/var/www/html/test">
    Order allow,deny
    Allow from all
</Directory>

But it still gives me the 403 forbidden error.

5
  • What are the permissions for the subdirectory like? Is there an index.html in the directory? What does your error_log say?
    – etagenklo
    Jun 7, 2013 at 14:34
  • @etagenklo Permissions for the subdirectory are: drwxrwxr-x 8 apache apache 4096 Jun 6 11:10 workshop-5.4
    – Danny
    Jun 7, 2013 at 15:00
  • 1
    @etagenklo Yes there is an index.html in the subdirectory, its permissions are: -rw-rw-r-- 1 apache apache 2398 Jun 6 11:10 index.html
    – Danny
    Jun 7, 2013 at 15:01
  • You should still check your error_log.
    – etagenklo
    Jun 7, 2013 at 15:05
  • I just created a new subdirectory without any files inside of it (the original one had many files and subdirectories, including an index.html). On the empty subdirectory it does allow me access though and just brings up the list of files inside that subdirectory (which is currently none).
    – Danny
    Jun 7, 2013 at 15:05

5 Answers 5

9

You should not need to specifically allow access to a directory below one which is already configured within httpd.conf

Since /var/www/html is configured with "AllowOverride None" then the problem is not due a .htaccess file changing the access rights.

The only remaining reason is that the permissions on the files and directories do not permit the webserver uid to read from this directory. What they are, and what they should be depends on your security model. But as a quick fix you could try:

# chmod a+rx /var/www/html/test
# chmod a+r /var/www/html/*

If this solves the problem then please take time to fix the ownership and permissions of the files to something more appropriate.

6
  • 1
    Tried this but still no fix. :\
    – Danny
    Jun 7, 2013 at 14:43
  • What are the permissions on the files? Did you verify that /var/www/html/test is not a symlink?
    – symcbean
    Jun 7, 2013 at 14:45
  • -rw-r--r-- 1 apache apache 92 Jun 6 10:57 index.html drwxrwxr-x 8 apache apache 4096 Jun 6 11:10 test
    – Danny
    Jun 7, 2013 at 14:53
  • Also for the index file inside the test folder: -rw-rw-r-- 1 apache apache 2398 Jun 6 11:10 index.html
    – Danny
    Jun 7, 2013 at 14:55
  • Looks like you've already got serious security problems. (if it's not the file permissions and it's not the webserver config then either you're looking in the wrong filesystem - httpd is runing chroot - or you've got selinux or acls preventing the access).
    – symcbean
    Jun 7, 2013 at 19:11
4

Usually I recommend to take a look first to http error_log to see the exact problem.

With default configuration you should be able to access workshop-5.4 directory:

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

If you still cannot access the directory everything points to directory permissions, in that case I suggest to try:

chown -R apache.apache /var/www/html  # Assuming apache as default User
chmod -R 755 /var/www/html            # Making sure all users can read and execute

On a separate terminal run following commands:

apachectl configtest && apachectl restart
tail -f /etc/httpd/logs/error_log     # Assuming default error_log location

Try to add a simple html file like (example.html):

<html>
<head><body>It works!</body></head>
</html>

Finally, reload the page, try to load example.html and take a look to the output of the tail command.

1
  • That's what I have right now though, and I still cannot access the subdirectory.
    – Danny
    Jun 7, 2013 at 14:41
0

Comment those <Directory> directives and simply set DocumentRoot /var/www/html and chown -R apache:apache /var/www/html and restart httpd.

The <Directory> directive should be used to apply group of directives to a specific filesystem directory (i.e. changing permissions), so you usually want to use it in a <VirtualHost>.

2
  • Tried this and restarted but still no access.
    – Danny
    Jun 7, 2013 at 14:46
  • ls -lR /var/www/html
    – fsoppelsa
    Jun 7, 2013 at 14:54
0

SE Linux was enabled in my case.

setenforce 0

to disable it (for testing purposes only)

0

One more case, in the comments it's mentioned that the directory was copied with files in it.

There could be an .htaccess file there with configuration causing the 403.

Files with names starting with a dot "." are hidden in Unix, to show them use ls -a .

Documentation here: https://httpd.apache.org/docs/current/howto/htaccess.html

You must log in to answer this question.

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