Change root of apache in LAMP (Ubuntu and Debian Linux)

This tutorial is for changing root directory of apache server on Debian system like Ubuntu. When you install apache (or LAMP) by default the root directory of apache is /var/www/html.
When doing development on local machine you might want to change this to some directory in your home directory. Advantage of doing this is you don’t need to change any permissions as your home directory will have full read write access to you. Else with /var/www/html you’ll have to use chown.

So let’s say we need to change the root of apache to /home/someuser/projects then follow below steps:

Step I: Update 000-default.conf

Open 000-default.conf file in vim by running below command.

Search for DocumentRoot and update it to look as below

Replace /home/someuser/projects with your path

Step II: Update apache2.conf

Open apache2.conf file in vim.

Search for below blog

Add below code right below above code

Again replace /home/someuser/projects with your path.

Step III: Restart apache

Restart apache server for above changes to take effect.

Now if you visit your website you can see the change.

Leave a Reply

Your email address will not be published. Required fields are marked *