Enable Apache UserDir In CentOS 7 / RHEL 7 with SELinux

Lets show you how to install userdir for Centos 7 with Selinux Enabled. In this method all users should have their own public_html directory.

1. Go to root user

su - root

2. Create /etc/httpd/conf.d/userdir.conf file

Install apache: 

yum install httpd -y

Enable Apache Userdirs

vi  /etc/httpd/conf.d/userdir.conf


<IfModule mod_userdir.c>
 # UserDir is disabled by default since it can confirm the presence
 # of a username on the system (depending on home directory
 # permissions).
UserDir enabled nixpal

 # To enable requests to /~user/ to serve the user's public_html
 # directory, remove the "UserDir disabled" line above, and uncomment
 # the following line instead:
 UserDir public_html


<Directory /home/*/public_html>
Options Indexes Includes FollowSymLinks
##For  apache 2.2,Please use:

 AllowOverride All
 Allow from all
 Order deny,allow
#For apache >= 2.4,Please  use :
  Require all granted


Restart apache

systemctl restart httpd.service

Then create user’s public_html and assign permissions.

mkdir /home/nixpal/public_html
chmod 711 /home/nixpal
chown nixpal:nixpal /home/nixpal/public_html
chmod 755 /home/nixpal/public_html

Then here’s the other new things, especially you are using SELinux

setsebool -P httpd_enable_homedirs true
chcon -R -t httpd_sys_content_t /home/nixpal/public_html

Lets make a test 

nano /home/nixpal/public_html/index.html


<div style="width: 100%; font-size: 30px; font-weight: bold; text-align: center;">
UserDir nixpal Test Page

Change ownership 

chmod 644 /home/nixpal/public_html/index.html

Run the test by navigating to the following URL from your browser.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.