Monday, 13 April 2015

HTTP (httpd) Home Directory Access in RHEL7/CentOS7


In this tutorial, we configure Apache to enable access a user's home directory.

Consider the following scenario:

HTTP Server IP Address: 192.168.122.3
                      Host Name: server2.mycompany.com

Server Configuration:

1)  Install httpd
[shabbir@server2 ~]$ sudo yum -y install httpd

2) Edit the file '/etc/httpd/conf/httpd.conf'. Make following changes:
[shabbir@server2 ~]$ sudoedit /etc/httpd/conf/httpd.conf
 
        ServerName server2.mycompany.com


3) Edit Config file '/etc/httpd/conf.d/userdir.conf'. Make following changes:
[shabbir@server2 ~]$ sudoedit /etc/httpd/conf.d/userdir.conf

# Disable this line 
      #UserDir disabled

# Enable this line 
      UserDir public_html

#Anyone will have access to web pages that a user puts in her ~/public_html/ directory. For eg, 'shabbir' can create a /home/shabbir/public_html/ directory and add web pages to it.


4) Check config file syntax errors
[shabbir@server2 ~]$  sudo httpd -t


5) Create directory to share '/home/shabbir/public_html'

[shabbir@server2 ~]$ mkdir public_html


6) Create a file  '/home/shabbir/public_html/index.html'
             <html>
             <body>
              <h1> Hello World  </h1>
              </body>
           </html>


7) Grant search (execute) permission on shabbir's home directory to user 'apache'.
[shabbir@server2 ~]$ setfacl  -m u:apache:x  /home/shabbir
[shabbir@server2 ~]$ setfacl  -m u:apache:x  /home/shabbir/public_html


8) Enable SELinux boolean
[shabbir@server2 ~]$ sudo setsebool -P httpd_enable_homedirs on

9) Open HTTP (Port 80) in firewall
[shabbir@server2 ~]$ sudo firewall-cmd --zone=public --add-service=http --permanent
[shabbir@server2 ~]$ sudo firewall-cmd --reload

10)  Start httpd
[shabbir@server2 ~]$ sudo systemctl start httpd

11)  Enable on boot
[shabbir@server2 ~]$ sudo systemctl enable httpd


Client Configuration:

1)  Make entry in '/etc/hosts' if DNS Server is not configured.
              192.168.122.3        server2.mycompany.com

2)  Install command-line browser 'elinks'
[shabbir@meru ~]$ sudo yum -y install elinks

3) Browse user home dir
[shabbir@meru ~]$ elinks http://server2.mycompany.com/~shabbir

No comments:

Post a Comment