Wednesday, February 4, 2015

[CentOS 7] : Linux Basics: How To Enable Apache UserDir In CentOS 7/RHEL 7

Linux Basics: How To Enable Apache UserDir In CentOS 7/RHEL 7

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
add:
<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 unixmenuser

 #
 # 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

</IfModule>

<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

</Directory>
Restart apache
systemctl restart httpd.service
Then create user’s public_html and assign permissions.
mkdir /home/unixmenuser/public_html
chmod 711 /home/unixmenuser
chown unixmenuser:unixmenuser /home/unixmenuser/public_html
chmod 755 /home/unixmenuser/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/unixmenuser/public_html
Lets make a test 
vi /home/unixmenuser/public_html/index.html
add:
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
UserDir unixmenuser Test Page
</div>
</body>
</html>
Change ownership 
chmod 644 /home/unixmenuser/public_html/index.html
Run the test by navigating to the following URL from your browser.
http://ip/~username
2015-01-30_142650
Done.

No comments: