Linux – Creating a public_html for a user on a Red Hat Linux Server

httpdlinuxredhatselinux

I'm just trying to make a public_html folder under my username on a Red Hat Linux Server
(and it's all been a bit of a headache).

I made the folder and set the permissions to 755.
I wasn't sure how to deal with Apache (and admittedly finding the httpd.conf file was a nightmare, thanks to an unconventional directory layout), but now I've found it, I'm not sure what to do.

I've seen this question; Setting up individually accessible public_html for each user of a linux machine, but I don't understand the answer. How can I 'use mod_userdir' (I'm quite new to all of this).

I've looked at this;
http://httpd.apache.org/docs/2.0/mod/mod_userdir.html

Am I supposed to append something for the 'httpd..conf file?

I tried appending 'UserDir enabled username' to the top, and restart Apache, but still I can't find a page at;
domain.com/~username/

What could the problem be?
Am I using mod_userdir incorrectly? (I don't even know HOW to use it)

Thanks!

Best Answer

What RedHat version do you have installed? On RedHat 6.x it's pretty straightforward:

1) let's assume I have a user ec2-user created with home directory /home/ec2-user

2) create a directory /home/ec2-user/public_html and make sure that directory /home/ec2-user and /home/ec2-user/public_html have set permissions at least 0711 (executable bit set on other means that apache user under which apache2 web server is running will have permission to enter these directories). Additionally, any content of that directory has to be readable by the apache user.

3) enable UserDir module in apache2 web server configuration which is available in the file /etc/httpd/conf/httpd.conf. Comment out the line UserDir disabled and uncomment the line UserDir public_html:

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

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

4) test apache2 web server configuration with httpd -t, it should return Syntax OK otherwise something went wrong

5) restart apache2 web server with service httpd restart and optionally, enable the service with chkconfig httpd on on boot

6) finally, if you have selinux enabled in enforcing mode - you can check it with sestatus - you have to run this command setsebool -P httpd_read_user_content=on to allow apache2 web server to read user content

7) test it, e.g. from the server run w3m http://localhost/~ec2-user, if there are any errors they should be logged to the log file /var/log/httpd/error_log