How to change Apache Document root directory on Ubuntu 18.04

To modify the root folder in Apache, you would need to make changes to two files basically. We will first start by modifying the file /etc/apache2/apache2.conf.

Run the command :
sudo vim /etc/apache2/apache2.conf

Or using your favorite editor.

Read: How to install Apache web server on Ubuntu

Now that the file is in edit mode, look up the command : DocumentRoot

This indicates the directory where all requests will be handled and documents read.

Go ahead and replace the line which starts with DocumentRoot with :

DocumentRoot [your_target_directory]

You would need to ensure that there is no permission issue so that Apache can access your folder in read/write modes.

Read: Virtual host configuration in Apache

Now do the same procedure above for the file :


Finally, save the files and restart Apache using the command:

systemctl restart apache2

This is the directory from which Apache will read the contents that the visitor will access over the browser.




If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.


Marianne elanotta

Marianne is a graduate in communication technologies and enjoys sharing the latest technological advances across various fields. Her programming skills include Java OO and Javascript, and she prefers working on open-source operating systems. In her free time, she enjoys playing chess and computer games with her two children.

Leave a Reply