7.9 C
Vancouver
Sunday, December 22, 2024

Fixing SELinux Content in a HTML directory

Must read

Unable to access web files in a directory under the /var/www/html becuase of a 403 forbidden might be a context problem.

Problem

Getting a 403 forbidden error message when accessing a new file or directory in /var/www/html.

Check /var/log/messages to see if there are any:

Sep 13 13:11:28 fserver02 kernel: audit(1221336688.892:14): avc:  denied  { getattr } for  pid=25036 comm=”httpd” name=”phpldapadmin” dev=dm-0 ino=2441537 scontext=root:system_r:httpd_t tcontext=root:object_r:user_home_t tclass=dir

Solution

First check the context on the root directory.

cd /var/www/html
ls -Z index.html
-rw-r–r–  root     root     root:object_r:httpd_sys_content_t index.html

Look at the context of the new directory or file

ls -Z index.php
-rw-r–r–  root     root     root:object_r:user_home_t index.php

Now change the file or directory to the correct context

chcon  root:object_r:httpd_sys_content_t . -Rc

Check the context of the file:

ls -Z index.php
-rw-r–r–  root     root     root:object_r:httpd_sys_content_t index.php

 

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article