Last active
September 26, 2018 15:34
-
-
Save tonejito/401311bab73c1fe23d617ad183e8a0b3 to your computer and use it in GitHub Desktop.
Fix @apache httpd issues with SELinux on CentOS 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0644 root:root ~/.bash_aliases | |
alias fix-apache-selinux='/usr/bin/sudo /usr/local/sbin/fix-apache-selinux' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 0755 root:root /usr/local/sbin/fix-apache-selinux | |
# https://wiki.centos.org/HowTos/SELinux | |
# https://wiki.centos.org/TipsAndTricks/SelinuxBooleans | |
# https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/ | |
OWNER=tonejito | |
GROUP=www | |
PREFIX=/var/www/html | |
cd ${PREFIX} | |
# Fix normal UNIX owner and permissions | |
chown -R "${OWNER}:${GROUP}" -R . | |
chmod -R ug+rw,o-w . | |
find . -type d -print0 | xargs -r -0 chmod g+s | |
## Set correct SELinux context with chcon | |
# chcon -R -t httpd_sys_content_t . | |
# chcon -R -t httpd_sys_rw_content_t ./sites/default/files | |
## Set default filesystem context for the path | |
# semanage fcontext -a -t httpd_sys_content_rw_t "${PREFIX}/sites/default/files(/.*)?" | |
# Restore default SELinux context | |
restorecon -R . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0440 root:root /etc/sudoers.d/fix-apache-selinux | |
Cmnd_Alias FIX_APACHE_SELINUX=/usr/local/sbin/fix-apache-selinux | |
%adm ALL=(root:root) NOPASSWD:FIX_APACHE_SELINUX | |
%wheel ALL=(root:root) NOPASSWD:FIX_APACHE_SELINUX | |
%operator ALL=(root:root) NOPASSWD:FIX_APACHE_SELINUX | |
%staff ALL=(root:root) NOPASSWD:FIX_APACHE_SELINUX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment