Change apache document root (www folder) in Fedora

Hello everybody!

Today I tried to install apache on Fedora 18. I need to change the root directory to ease me editing file and avoiding permission. It is quite different when I was configuring on ubuntu. Also I did this when I first using Fedora(Fedora 18 is my first fedora flavour), but being lazy I did not write the steps to my blog, so this time I need to go through several forums/blog again and  I come to this post. So, I won’t be crazy for the next time. 😛

The default root directory is at /var/www/html. In my case, I want to change it to /home/user1/web.
Step 1: Edit apache configuration file (as root)
# gedit /etc/httpd/conf/httpd.conf
Find these two lines
DocumentRoot “/var/www/html”
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory “/var/www/html”>
Then, change to
DocumentRoot “/home/user1/web”
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory “/home/user1/web”>
Save and close this file.
Step 2: Changing permission
# chmod 711 /home/user1
# chmod -R 755 /home/user1/web
This step is necessary since in fedora, httpd process will be executed by user ‘apache’, thus permission need to be change.
By default, the permission for each user directory is drwx——, so that other users can’t access to files in this directory and its subdirectories.
# setsebool -P httpd_enable_homedirs 1
# chcon -R -t httpd_sys_content_t /home/user1/web
Note: httpd by default is not allowed to access users home directories, see this page
Step 3: Restart apache
# service httpd restart
Hope this may help some new-bee a little bit 🙂
N.B. This is a draft post published today. Right now I am using Fedora 19 and This process works like charm here.
(Visited 767 times, 1 visits today)

Leave a comment

Your email address will not be published. Required fields are marked *