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.

Now do the same procedure above for the file :

/etc/apache2/sites-enabled/000-default

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 browser.

Read: How to use systemd to troubleshoot Linux problems


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

As a graduate in communication technologies, Marianne likes to share the latest technological advances in various fields. She likes to program in Java OO and Javascript and prefers to work on Open source operating systems. She likes to play chess and computer games in her spare time along with her 2 kids.

Leave a Reply