How to Find Apache Document Root in Linux

The DocumentRoot is the top-level directory in the document tree visible from the web and this directive sets the directory in the configuration from which Apache2 or HTTPD looks for and serves web files from the requested URL to the document root.

For example:

DocumentRoot "/var/www/html"

then access to http://domain.com/index.html refers to /var/www/html/index.html. The DocumentRoot should be described without a trailing slash.

In this short quick tip, we will show you how to find the Apache DocumentRoot directory in a Linux system.

Finding Apache Document Root

To get the Apache DocumentRoot directory on Debian, Ubuntu Linux and it’s derivatives such as Linux Mint, run the following grep command.

$ grep -i 'DocumentRoot' /etc/apache2/sites-available/000-default.conf
$ grep -i 'DocumentRoot' /etc/apache2/sites-available/default-ssl.conf
Find Apache DocumentRoot in Ubuntu
Find Apache DocumentRoot in Ubuntu

On CentOS, RHEL and Fedora Linux distributions, run the following command.

$ grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf
$ grep -i 'DocumentRoot' /etc/httpd/conf.d/ssl.conf
Find Apache DocumentRoot in CentOS
Find Apache DocumentRoot in CentOS

Note that the location of the DocumentRoot directory may vary depending on the value of the DocumentRoot directive set in the Apache or httpd configuration.

If you want to change the location of the Apache DocumentRoot directory, please read our article that explains How to Change Default Apache ‘DocumentRoot’ Directory in Linux.

On a side note, the individual directories for all your virtual hosts must be located under the DocumentRoot. For example, if your DocumentRoot is /var/www/html, and you have two sites called example1.com and example2.com, you can create their directories as shown.

$ sudo mkdir -p /var/www/html/example1.com/
$ sudo mkdir -p /var/www/html/example2.com/

Then in the virtual host configuration files, point their DocumentRoot to the above directories.

Here are some additional guides about Apache web server, that you will find useful:

  1. Useful Commands to Manage Apache Web Server in Linux
  2. 3 Ways to Check Apache Server Status and Uptime in Linux
  3. How to Enable Apache Userdir Module on RHEL/CentOS
  4. Apache Virtual Hosting: IP Based and Name-Based Virtual Hosts
  5. How to List All Virtual Hosts in Apache Web Server

That’s It! If you know any other useful way to find the Apache DocumentRoot directory, do share with us in the comment section below.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 thought on “How to Find Apache Document Root in Linux”

Leave a Reply to grant amaral Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.