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 DebianUbuntu 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 CentOSRHEL 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.

Source: https://www.tecmint.com/find-apache-documentroot-in-linux/

Leave a Reply

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