How To Find Apache Document Root

Q. How do I find out my Apache webserver document root under Linux / UNIX / BSD operating systems?

A. Apache has DocumentRoot directive.

This directive sets the directory from which Apache will serve files. Unless matched by a directive like Alias, the server appends the path from the requested URL to the document root to make the path to the document. Example:

DocumentRoot /home/www/theos.in

then an access to http://www.theos.in/index.html refers to /home/www/theos.in/index.html.

Finding Apache Document Root

Use grep command as follows:
# grep -i 'DocumentRoot' httpd.conf
RHEL / Red hat / Fedora / CentOS Linux specific command:
# grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf
FreeBSD specific command:
# grep -i 'DocumentRoot' /usr/local/etc/apache22/httpd.conf
Sample output:

# DocumentRoot: The directory out of which you will serve your
DocumentRoot "/usr/local/www/apache22/data"

/usr/local/www/apache22/data is default document root for your website.

To modify DocumentRoot use vi command and change DocumentRoot:
# vi /etc/httpd/conf/httpd.conf


🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Neang chanraksmey Jun 17, 2011 @ 2:02

    i want to ask you about Linux question
    – what does documentRoot mean in webserver configuration?
    – what are the run levels? Explain them briefly?

  • Unsa Tisfied Feb 11, 2014 @ 5:42

    And what if there is no document root specified in the httpd.conf file??? What is the default document root? Is there a way to query apache from the terminal for this value?

  • Kak Aug 15, 2015 @ 9:18

    If you know where httpd.conf is, you automatically know where your www root is. I wonder why one thought that an article like this is useful.

Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz