joginayak
By:
joginayak

"Forbidden - You don't have permission to access / on this server" Error

January 7, 2017 215 views
Apache Ubuntu 16.04

I followed the virtual hosts tutorial and set up apache for my domain name aditidentalcare.com. The website was loading perfectly but now I am suddenly getting this error.

Forbidden - You don't have permission to access / on this server.

I don't understand why!

Here is the aditidentalcare.com.conf

<VirtualHost *:80>
ServerAdmin jogi@smashingpixels.in
ServerName aditidentalcare.com
ServerAlias www.aditidentalcare.com
DocumentRoot /var/www/html/sites/aditidentalcare.com/public_html
ErrorLog /error.log
CustomLog /access.log combined
</VirtualHost>

The permission for public_html is set to 750 and the owner:group is jogi:www-data

1 Answer
jtittle January 7, 2017
Accepted Answer

@joginayak

You need to use chmod 755 instead of 750 on directories. Using 750 equates to users having read, write, and execute, groups having read and execute, and finally, world (i.e your visitors) having absolutely zero access, thus they will be forbidden from accessing and/or viewing the contents.

  • Can't believe I didn't think of that :P. Thanks a lot man. It worked! Do you think it's safe to let the rest of the world 'execute' on my server?

    • its a good practice to have folders with 755 and files with 644 permission

      and sensitive files should be 700

      • Done man. Thanks a lot.

        • @joginayak
          i think i made a mistake there, sensitive files which are related with security should be with chmod 600

          apology for my mistake

          • @joginayak

            When it comes to sensitive files, they shouldn't be in the web root to begin with :-).

            Having a CHMOD of 755 on directories and 644 on files is preferred. If files are too sensitive too risk public access (i.e. session data files, for example), they shouldn't be in an area that can be accessed by the public at all.

            For example, when it comes to application setup, I'll often use a structure such as:

            /home/username/htdocs/public
            /home/username/htdocs/private
            /home/username/htdocs/storage
            

            All public files go in public, private (class files, for example) in private and everything else in the storage directory (when appropriate).

Have another answer? Share your knowledge.