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:

1 comment: