Changing the Default File Type

Under some circumstances, you might need to change the default file type for a file system hierarchy. For example, you might want to use a DocumentRoot directory other than /var/www/html with httpd.

To change the default file type of the directory hierarchy /var/webcontent to httpd_sys_content_t:

  1. Use the semanage command to define the file type httpd_sys_content_t for the directory hierarchy:

    # /usr/sbin/semanage fcontext -a -t httpd_sys_content_t "/var/webcontent(/.*)?"

    This command adds the following entry to the file /etc/selinux/targeted/contexts/files/file_contexts.local:

    /var/webcontent(/.*)?     system_u:object_r:httpd_sys_content_t:s0
  2. Use the restorecon command to apply the new file type to the entire directory hierarchy.

    # /sbin/restorecon -R -v /var/webcontent