The document root (also called as the web root) of the Apache web server is located at the /var/www directory by default. Document root is the place where we find all the web pages and server scripts. These files are loaded on the browsers when we type in a particular url to point to that server.
The /var/www directory doesn't allow access for a user who doesn't have the root permission. It's a headache task to switch to the root mode by typing in the root password everytime even though you know the password, since you may have to change your webpages or scripts during its development stage very frequently. So a better idea to avoid this problem is to change the default Document root directory to some other location which doesn't require root permission for access.
Change it dude !!!
- - - - - - - - - - - - - - - - - -#
Inorder to change the document root,
#1. Make a directory somewhere inside your home directory to use as the Document root. (not necessarily be home... you can make it anywhere). I named it 'www'
$ mkdir /home/jo/www
#2. Now we have to edit the one of the configuration file of the Apache webserver. The file is located @ /etc/apache2/sites-available/default (requires root permission to edit it).
$ sudo gedit /etc/apache2/sites-available/default
The file will be opened up in the gedit text editor. Now you have to edit the DocumentRoot directive in this file. Replace the /var/www with the /path/to/your/new/document/root in the lines 4 and 9 as shown in the figure below.
#3. Restart the apache webserver.
$ sudo /etc/init.d/apache2 restart
Now test it !!!
- - - - - - - - - - - - - - - - - -#
#1. Create a html/php file inside the Document Root directory (mine is @ /home/jo/www).
#2. Take the terminal and navigate to the Document Root directory (using cd command). Use chmod command given below to allow read+write+execute permission to all.
$ chmod 777 *
#3. Take your web browser and type in http://localhost and hit the enter key! The apache server will load the contents of your Document Root directory as in the figure.
Hope you have done it right!!!