Apache HTTP web server

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

In this tutorial I will tell you, How to install and configure the Apache server.

Apache is also known as httpd (Http daemon).

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

Installing Apace in Ubuntu

You must have administrative privilege

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 will show 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.