.html
files for that website with the httpd_sys_content_t
type. By default, the Apache HTTP Server can not write to files that are labeled with the httpd_sys_content_t
type. The following example creates a new directory to store files for a read-only website:
mkdir /mywebsite
as the root user to create a top-level directory.
/mywebsite/index.html
file. Copy and paste the following content into /mywebsite/index.html
:
<html> <h2>index.html from /mywebsite/</h2> </html>
/mywebsite/
, as well as files and subdirectories under it, label /mywebsite/
with the httpd_sys_content_t
type. Run the following command as the root user to add the label change to file-context configuration:
# semanage fcontext -a -t httpd_sys_content_t "/mywebsite(/.*)?"
restorecon -R -v /mywebsite
as the root user to make the label changes:
# restorecon -R -v /mywebsite restorecon reset /mywebsite context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /mywebsite/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
/etc/httpd/conf/httpd.conf
as the root user. Comment out the existing DocumentRoot
option. Add a DocumentRoot "/mywebsite"
option. After editing, these options should look as follows:
#DocumentRoot "/var/www/html" DocumentRoot "/mywebsite"
service httpd status
as the root user to see the status of the Apache HTTP Server. If the server is stopped, run service httpd start
as the root user to start it. If the server is running, run service httpd restart
as the root user to restart the service (this also applies any changes made to httpd.conf
).
http://localhost/index.html
. The following is displayed:
index.html from /mywebsite/