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:
000-default.conf
Open 000-default.conf
file in vim by running below command.
1 |
sudo vim /etc/apache2/sites-available/000-default.conf |
Search for DocumentRoot and update it to look as below
1 |
DocumentRoot /home/someuser/projects |
Replace /home/someuser/projects
with your path
apache2.conf
Open apache2.conf
file in vim.
1 |
sudo vim /etc/apache2/apache2.conf |
Search for below blog
1 2 3 4 5 |
<Directory /> Options Indexes FollowSymLinks AllowOverride None Require all denied </Directory> |
Add below code right below above code
1 2 3 4 5 |
<Directory /home/someuser/projects/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> |
Again replace /home/someuser/projects with your path.
Restart apache server for above changes to take effect.
1 |
sudo service apache2 restart |
Now if you visit your website you can see the change.