Changing the Default File Type

This task shows you how to change the default file type for a file system hierarchy. In the example, you have chosen to use a different DocumentRoot directory for httpd than the default /var/www/html.

  1. Specify the new default file type for the directory hierarchy.

    To change the default file type of the directory hierarchy /var/webcontent to httpd_sys_content_t, use the semanage command:

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

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

    /var/webcontent(/.*)?     system_u:object_r:httpd_sys_content_t:s0
  2. Apply the new file type to the directory hierarchy:

    Use the restorecon command to apply the new file type to the entire directory hierarchy:

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