Red Hat System Administration II
Configure Apache to publish web content from users' home directories.
Outcomes
Configure the Apache web service to publish web content from the user's home directory.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start selinux-booleans
Instructions
On the
workstationmachine, use thesshcommand to log in to theserveramachine as thestudentuser and then switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Edit the
/etc/httpd/conf.d/userdir.confconfiguration file to enable the Apache feature so that users can publish web content from their home directory. Comment out the line in theIfModulesection that sets theUserDirvariable to thedisabledvalue, and uncomment the line that sets theUserDirvariable to thepublic_htmlvalue.[root@servera ~]#
vim /etc/httpd/conf.d/userdir.conf<IfModule mod_userdir.c> ...output omitted... # UserDir disabled ...output omitted... UserDir public_html ...output omitted... </IfModule>Start and enable the Apache web service.
[root@servera ~]#
systemctl enable --now httpdOpen another terminal window, and use the
sshcommand to log in to theserveramachine as thestudentuser. Create theindex.htmlweb content file in the~/public_htmldirectory.In another terminal window, use the
sshcommand to log in to theserveramachine as thestudentuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$Use the
mkdircommand to create the~/public_htmldirectory.[student@servera ~]$
mkdir ~/public_htmlCreate the
index.htmlfile with the following content:[student@servera ~]$
echo 'This is student content on SERVERA.' > \~/public_html/index.htmlFor the Apache web service to serve the contents of the
/home/student/public_htmldirectory, it must be allowed to share files and subdirectories in the/home/studentdirectory. When you created the/home/student/public_htmldirectory, it was automatically configured to allow anyone with home directory permission to access its contents.Change the
/home/studentdirectory permissions to allow the Apache web service to access thepublic_htmlsubdirectory.[student@servera ~]$
chmod 711 ~[student@servera ~]$ls -ld ~drwx--x--x. 16 student student 4096 Nov 3 09:28 /home/student
Open a web browser on the
workstationmachine and enter thehttp://servera/~student/index.htmladdress. An error message states that you do not have permission to access the file.Switch to the other terminal, and use the
getseboolcommand to see whether any Booleans restrict access to home directories for thehttpdservice.[root@servera ~]#
getsebool -a | grep home...output omitted...httpd_enable_homedirs--> off ...output omitted...Use the
setseboolcommand to enable persistent access to the home directory for thehttpdservice.[root@servera ~]#
setsebool -P httpd_enable_homedirs onVerify that you can now see the
This is student content on SERVERA.message in the web browser after entering thehttp://servera/~student/index.htmladdress. You might need to close and reopen your web browser to see the message.Return to the
workstationmachine as thestudentuser.[root@servera ~]#
exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$