Monday, April 19, 2010

Fedora: Change Root Directory of Httpd

I recently try to install apache on fedora 12. 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. After read through several forums I come to this post. So, I won't be crazy for the next time.. haha

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 will help a little bit :)

References:

13 comments:

  1. Thanks... just what I was looking for...

    ReplyDelete
  2. Yes! thank you.. exactly what I needed. Just made the switch from Debian and almost went back over this issue.

    ReplyDelete
  3. except.. it still won't let the webserver write to the folder, and any new files/folders I create have the default se permissions. still unusable. *sigh*

    ReplyDelete
  4. Thank you very much!

    ReplyDelete
  5. Change is successful. Apache restarts OK, but the following message is printed in the browser:

    You don't have permission to access / on this server.

    ReplyDelete
  6. thanks man, it helped me a lot, although it definitively put out a fight

    ReplyDelete
  7. I have problem with setsebool -P httpd_enable_homedirs 1 - it start working on something, but never end. Can someone help me?

    ReplyDelete
  8. Worked for me too, in new Fedora 20!
    I did everything but in httpd.conf
    The solution came from setsebool & chcon
    I am very gratefull!

    ReplyDelete
  9. Very nice! functionou perfectly! would you allow me to publish on my blog here in Brazil?

    ReplyDelete