Apache web server is one of the most used web servers across all the platforms even after including different Linux distributions and windows. Apache server is an open source HTTP server that is mainly used to deliver web content and can also be used to serve many queries at once.
In this article, I will try to explain how to change the root directory for Apache web server.
It is usually the case that to change the root directory we must first be aware of its exact location and in the case of the Apache server, the root directory which is also known as DocumentRoot is present inside the folder −
The DocumentRoot is the directory from which the Apache server will read the contents that the visitor will access over the internet.
Sometimes it is the case that the default DocumentRoot can also be present inside the directory.
Now the next step is to locate the file in which this DocumentRoot is configured. Just type the following command in the terminal −
Now next step is to open this .conf file in your favorite text editor, I am making use of nano, and so the command for me looks something like this −
sudo nano /etc/apache2/sites-available/000-default.conf
and now we need to find the text “DocumentRoot” in the above file and change the location that might look something like this −
To whatever destination you want.
We also need to make a similar change in the apache2.conf file, for that just type the following command to the terminal
sudo nano /etc/apache2/apache2.conf
And then, try to find the following content in the above file
<Directory /var/www/html/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
Now just change the /var/www/html to the directory that you changed to in the default.conf file and save your file and restart the server with the command shown below −
sudo service apache2 start