Pages

Changing The default Root Document Directory in Apache Web Server

When we install the Apache Web Server on a System, It set the Default Root Document Directory to "/var/www/html" OR "/var/www", depends on the version, to serve the user request.




One can check the default Root Document Directory by checking the file "000-default.conf" under the directory "/etc/apache2/sites-available" and search the "DocumentRoot" inside the file "000-default.conf".
 
DocumentRoot /var/www/html  # This is the Default Root Document Directory

Sometime We want to change the default Root Document Directory to some other directory.

Suppose we want to share some music file with our friends using http and our music file resides inside the directory "/home/techieknowledge/Music". This directory contains my collection of music, and I want to share it.

To make this possible we want Apache web Server to serves  files from the "/home/techieknowledge/Music" instead of Default Root Document directory which in this case is "/var/www/html".

To chang the Default Directory we follow below step.
Step 1. Go to Directory "/etc/apache2/sites-available"
       

$ cd /etc/apache2/sites-available


Step 2. Open the file "000-default.conf"  and Replace the /var/www/html to "/home/techieknowledge/Music"

Step 3. Now go to /etc/apache and open the file "apache2.conf"

and add folowing  give line to "apache2.conf"


<Directory /home/techieknowledge/Music>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>


Step 4. Now restart the Apache


$ sudo /etc/init.d/apache2 restart

Now type http://localhost/  on
your browser and you will see listing of your Music files and directory  in your browser.



Now you can share your file with your friends.

No comments:

Post a Comment