I'm currently running Centos 7 and configuring SELinux enabled, currently I configure my apache docroot under the /home/user/public_html and files/folders show the context label:
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 readme.html
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-activate.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-admin
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-blog-header.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-comments-post.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-config-sample.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-content
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-cron.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-includes
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-links-opml.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-load.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-login.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-mail.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-settings.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-signup.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-trackback.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 xmlrpc.php
I want to assign and change current context label httpd_user_content_t
to httpd_user_script_exec_t
recursively and apply only for all .php file types under public_html/. I already tried below code but the context still not changed:
# sudo semanage fcontext -a -t httpd_user_script_exec_t "/home/user/public_html/.*\.php"
# sudo restorecon -Rv public_html
# ls -Z
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 readme.html
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-activate.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-admin
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-blog-header.php