25

I can access localhost but not the sub directories index.html

My default conf looks like:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/*/>
    Allow from None
    Order allow,deny
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Even after allowing read/edit/write access to the directory, its showing Forbidden error. Tried all possible ways out in forums, didnt worked. Anyone has a solution.

Between above I tried something for sub directory access:

<Directory /var/www/*/>
    Allow from None
    Order allow,deny
</Directory>

Please suggest me possible solution. Thanks!

2 Answers 2

25

Let's make the vhost clear:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Then make sure you set the right permission like this:

sudo adduser <username> www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www
4
  • I did so. Still the same. Restarted apache as well. Should I try to modify in apache.conf instead? May 9, 2013 at 10:18
  • Here is the thing. I tried to change root directory, to my home folder index and its still pointing to /var/www. Gotta find right conf file. May 9, 2013 at 10:24
  • 1
    Just great. Only neede to add the www-data user. now all my local network user can use the content
    – DearDhruv
    Apr 23, 2015 at 11:59
  • I must say this is really frustrating Mar 20, 2020 at 15:07
3

This works for me, very well:

<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>

Checkout this tutorial: https://www.tecmint.com/forbidden-you-dont-have-permission-to-access-on-this-server-error/

You must log in to answer this question.

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