How to change apache web server document root in ubuntu

The default Apache2 web server document root is /etc/www/html. This can be sometimes annoying because of permission issues. You can change the default apache web server document root folder to a new folder in your Home folder.

Change apache web server document root in ubuntu

Here my Apache version: 2.4.18 (Ubuntu 16.04)

To change the default Apache2 web server document root ie: /etc/www/html/ to any other folder in Home folder ie: /home/manikandan/www/

Here manikandan is my ubuntu username. (replace it with your username)
and  www is a folder in the ubuntu Home directory. (create a www folder in your ubuntu home folder.)

Open the 000-default.conf file using below command in terminal.

sudo gedit /etc/apache2/sites-available/000-default.conf

and then type your password.

Find below line in 000-default.conf file

DocumentRoot /etc/www/html

apache2

and replace it with below line

DocumentRoot /home/manikandan/www

Save it and close it. The type the below command in terminal.

sudo gedit /etc/apache2/apache2.conf

It will open the apache2.conf file. Find the below line in that file

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

apache2 config

And replace it with the below line

<Directory /home/manikandan/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Save and close this file. Restart Apache using below command

sudo service apache2 restart

Now open http://localhost/ in your browser it should work as expected. If you are having trouble please leave a comment.

If you liked this article, please subscribe to our YouTube Channel. You can also stay connected with us on X (Twitter) and Facebook.



Also Read:  Linux Show Player - Cue Player For Stage Productions

Leave a Reply