
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
1 |
su - root |
2. Create /etc/httpd/conf.d/userdir.conf file
Install apache:
1 |
yum install httpd -y |
Enable Apache Userdirs
1 |
vi /etc/httpd/conf.d/userdir.conf |
add:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<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 </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
1 |
systemctl restart httpd.service |
Then create user’s public_html and assign permissions.
1 |
mkdir /home/nixpal/public_html |
1 |
chmod 711 /home/nixpal |
1 |
chown nixpal:nixpal /home/nixpal/public_html |
1 |
chmod 755 /home/nixpal/public_html |
Then here’s the other new things, especially you are using SELinux
1 2 |
setsebool -P httpd_enable_homedirs true chcon -R -t httpd_sys_content_t /home/nixpal/public_html |
Lets make a test
1 |
nano /home/nixpal/public_html/index.html |
add:
1 2 3 4 5 6 7 |
<html> <body> <div style="width: 100%; font-size: 30px; font-weight: bold; text-align: center;"> UserDir nixpal Test Page </div> </body> </html> |
Change ownership
1 |
chmod 644 /home/nixpal/public_html/index.html |
Run the test by navigating to the following URL from your browser.
1 |
http://ip/~username |