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

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.

Apache HTTP web server

What is Web Server ?

The HTTP server is a piece of software that understand URLs (web page addresses) and HTTP protocol.

This tutorial will tell you, How to install and configure the Apache web server.

Apache web server is also known as "httpd" (Http daemon).

A daemon is a process that is continuously running as background process.

Installing Apace in Ubuntu

Before installation, You must insure, you have a administrative privilege.

Steps to install Apache web server 

Step 1.  Update the system using the following command

$ sudo apt-get update
$ sudo apt-get install
Step 2. Now type the below command to install apache 

$ sudo apt-get install apache2

Now your apache web server is installed.

apache by default runs on port number 80.
To check you can use nmap command

type nmap localhost it will show you port 80 as in given screen shot

This will shows your apache httpd installed successfully.

Now you type the localhost on your browser address bar. It shows you apace default page.

Now you are ready to run your application using apache.

Apache configuration files

Apache2 is configured by placing directives in plain text configuration files.

Here we show some main configuration files --

go to cd /etc/apache2

apache2.conf : This is the  main Apache2 configuration file. This file Contains settings that are global to Apache2. It puts the pieces together by including all remaining configuration files when starting up the web server.

ports.conf : is always included from the main configuration file. It is supposed to determine listening ports for incoming connections which can be customized anytime.

Document root directory :  /var/www/html or /var/www

Where are the Apache log files?

By default, Error Log files of Web Server /var/log/apache2/error.log

Access Log files of Web Server: /var/log/apache2/access.log

Start, Stop and Restart Apache

After you have installed Apache, it will be added to the init.d list and will auto start whenever you boot up your computer. The following commands allow you to start, restart, stop Apache.

$ sudo /etc/init.d/apache2 start   #start apache
$ sudo /etc/init.d/apache2 stop   #stop apache
$ sudo /etc/init.d/apache2 restart   #restart apache

Changing the default port of apache

As we know that by default apache listen request to 80 port. some time there may be need to change default port number. 

steps to change the default port

Step 1. Open /etc/apache2/ports.conf

$ sudo vim /etc/apache2/ports.conf
search for 'Listen' 

and change 80 to your choice of port number say we want to run apache in port 8010

so we just edit Listen 80 to Listen 8010

Step 2 : Restart the apache

$ sudo /etc/init.d/apache2 restart

Now type in browser http://localhost:8010/ to check your changes.