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.

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

Search for DocumentRoot and update it to look as below

DocumentRoot /home/someuser/projects

Replace /home/someuser/projects with your path

Step II: Update apache2.conf

Open apache2.conf file in vim.

sudo vim /etc/apache2/apache2.conf

Search for below blog

    Options Indexes FollowSymLinks
    AllowOverride None
    Require all denied

Add below code right below above code

    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

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

Step III: Restart apache

Restart apache server for above changes to take effect.

sudo service apache2 restart

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 *