Apache Tips : Moving the Default DocRoot for Apache on Centos 6 December 14, 2012Posted 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 .
- The DocumentRoot directive
- 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 .