I ran those commands and now http://localhost wont render the index.html. Is there a way to fix it to work?
I know nothing about SeLinux stuff but I wanted my scripts to be able to write to that directory and I wanted it to render my html pages.
Errigour@DELL-7050:/srv/http/cgi-bin> sudo semanage fcontext -a -t httpd_sys_content_t "/srv/http"
File context for /srv/http already defined, modifying instead
Errigour@DELL-7050:/srv/http/cgi-bin> sudo restorecon -Rv /srv/http
Errigour@DELL-7050:/srv/http/cgi-bin> sudo semanage fcontext -a -t httpd_sys_rw_content_t "/srv/http"
File context for /srv/http already defined, modifying instead
Errigour@DELL-7050:/srv/http/cgi-bin> sudo restorecon -Rv /srv/http
Relabeled /srv/http from unconfined_u:object_r:httpd_sys_content_t:s0 to unconfined_u:object_r:httpd_sys_rw_co
ntent_t:s0
Errigour@DELL-7050:/srv/http/cgi-bin>
[Tue Nov 18 00:58:17.833310 2025] [core:error] [pid 1142:tid 1142] (13)Permission denied: [client 127.0.0.1:36182] AH00035: access to /index.html denied (filesystem path '/srv/http/index.html') because search permissions are missing on a component of the path
I think my problem before was I used this command on my http root directory: restorecon -Rv '/srv/http'
It restored index.html because it was recursive. That is why I had to chcon the index again. Pros more security, cons more commands to setup. I like SELinux but I saw a post talking about using apparmor. I don’t even think apparmor is installed on my system. Am I fixing this the right way?
AFAIK The changes made with chcon are temporary but with semanage it is permanent. A relabel due to a update in selinux should remove the changesdone with chcon.
No, they are not. chcon modifies file attributes which are stored permanently. But if SELinux policy has different definition for the file security label, it will be overwritten next time relabel is triggered (usually on SELinux packages update).
If the file in question is not referenced (directly or indirectly) in the SELinux policy, chcon is as permanent as you can get.
One can use matchpathcon to see what label is defined in the policy and will be set by the restorecon (which is invoked during relabel).