Fix 403 error in webserver caused by SELinux

Usually, to fix the 403 browser error for a directory, you should issue:

sudo chcon -R -t httpd_sys_content_t /path/to/www/data
Red Hat Enterprise version 4 introduced SELinux to our offering of Linux operating systems.

It is possible for any given web document on your server to have the correct permissions to be viewable from the web, but the httpd daemon will not be able to read it, unless you assign the correct security context or daemon access permissions. Context related errors usually show up as 403 errors when viewed from a web browser.

When a new file is created, it inherits the security context of its parent directory:
  • httpd_sys_content_t - The type used by regular static web pages with .html and .htm extensions
  • httpd_sys_script_ro_t - Required for CGI scripts to read files and directories
  • httpd_sys_script_ra_t - Same as the httpd_sys_script_ro_t type but also allows appending data to files by the CGI script
  • httpd_sys_script_rw_t - Files with this type may be changed by a CGI script in any way, including deletion
  • httpd_sys_script_exec_t - The type required for the execution of CGI scripts

To see current context, issue (works on RedHat family distributions):
ls -Z