jump to navigation

Apache Tips : Moving the Default DocRoot for Apache on Centos 6 December 14, 2012

Posted by Tournas Dimitrios in Apache-Tips.

On an Apache HTTP Server , you can control where the server looks to serve the documents (web-pages) . Most web-based control panels set this up for you by default when virtual hosts are created .The default documents directory depends on the Linux distribution . Common default locations are /var/www , /var/www/html, /home/user/www/html ,/home/user/public_html , /home/user/www/htdocs (and many other paths). If you want to change your default DocumentRoot path , there are at least two things you need to update into your Apache’s configuration file .

  1. The DocumentRoot directive
  2. The <Directory> block associated with the DocRoot .

As each DocumentRoot needs a matching block , be sure to update both to reflect the new location . If you only change the DocumentRoot path , you will get a 403 Forbidden error in your browser .These steps not only apply to the main server config, but also any VirtualHosts you want to change .

The following example is taken from my CentOs 6.3 box :

[root@aws-server]# vi /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html"
<directory "="" var="" www="" html"="">
 Options FollowSymLinks
 AllowOverride All
 Order allow,deny
 Allow from all


Make sure you do not use a trailling slash in the path . With the above configuration , the index.html file (or index.php ) at http://yourdomain.com will appear on the web .Make sure the directory you set as the document directory is readable but not writable to outside users . Finally , don’t forget to restart Apache .


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s