How to Change Default Apache ‘DocumentRoot’ in Linux
The word, Apache, has been taken from the name of the Native American tribe ‘Apache’, well known for its skills in warfare and strategy making. Apache is the most broadly used web server software. Apache is a freely accessible Web server that is distributed under an “open source” license. It is quick, dependable, and secure. The web server is used to deliver web content and can serve numerous queries at once.
So essentially a web server is the software that gets your request to access a website page. It runs a couple security check on your HTTP request and takes you to the website page. Depending on the page you have requested, the page may request that the server run a couple of additional modules while generating the document to serve you. It then serves you the document you requested.
It is a modular, process-based web server application that creates a new thread with each concurrent connection. It supports various features; huge numbers of them are compiled as separate modules and extend its core functionality, and can give everything from server side programming language support to verification system. Virtual hosting is one such feature that permits a single Apache Web Server to serve various different sites.
The change of default document root is an easy task that can be completed in a couple of minutes. This guide explains how to change Apache web server DocumentRoot on Linux.
Install Apache Web Server:
If apache web server is not installed on server then use below command to install it.
On CentOS/RHEL # yum install httpd On Ubuntu/Debian # apt-get install apache2
Find Apache DocumentRoot:
Run the following command to find Apache DocumentRoot.
On CentOS/RHEL # grep -r 'DocumentRoot' /etc/httpd On Ubuntu/Debian # grep -r 'DocumentRoot' /etc/apache2
Sample Output:
/etc/httpd/conf/httpd.conf:# DocumentRoot: The directory out of which you will serve your /etc/httpd/conf/httpd.conf:DocumentRoot "/var/www/html" /etc/httpd/conf/httpd.conf: # access content that does not live under the DocumentRoot.
Change Apache DocumentRoot:
To make the changes you need to modify in Apache’s configuration file. The default DocumentRoot for Apache is:
/var/www/html
These paths are described in the Apache’s configuration file.
CentOS/RHEL: /etc/httpd/conf/httpd.conf Ubuntu/Debian: /etc/apache2/sites-enabled/000-default /etc/apache/apache2.conf
To change the document root for your Apache web server simply open the file with your text editor and search for DocumentRoot.
# # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/home/apache2"
Once you have modified the DocumentRoot, restart apache using below commands:
On CentOS/RHEL 7 # systemctl restart httpd On CentOS/RHEL 6/5 # service httpd restart On Ubuntu # service apache2 restart
Enjoy it!