Skip to main content

How To Install Apache HTTP Web Server On Ubuntu

YouTube Video

INTRODUCTION


Apache Web Server is an open source software package. This means it can be used freely without requiring any purchases.
The official name is Apache HTTP Server.
It is a software package that turns a computer into an HTTP web server. This means that it sends web pages stored as HTML files to users who request them on the internet.
It runs on 67% of all web servers in the world. It is fast, reliable and secure. It can be highly customized to meet the needs of different environments using modules and extensions.
This guide will help you install the Apache Web Server on Ubuntu.

Prerequisites
  • A computer running Ubuntu Operating System 18.04 LTS (Bionic Beaver)
  • Good/stable Internet Connection
  • A user account with sudo or root privilege
Tools Needed
  • Terminal or Command line (Ctrl + Alt + T)
  • A firewall. The default Ubuntu Firewall is okay. (UFW - Uncomplicated Firewall)
  • The apt package manager which is installed by default on Ubuntu.
Installation Procedure
Before installing new software, it is necessary to update your local software package database in order to ensure that you are accessing the latest versions.
It helps prevent zero day exploits against outdated software and also saves on the time used to update after installation.
Open the terminal (Ctrl + Alt + T) or right click on the desktop and click open terminal and type the following command:
 sudo apt-get update  
Wait for the package manager to finish updating. Shouldn't take long
Install Apache 
Install the Apache package on Ubuntu using the following command:
 sudo apt-get install apache2 -y  
Verify Apache installation
Open a web browser and type in the address bar
 http://local.server.ip  
Replace the local.server.ip with the IP address of your server. To get the IP address of your server, type the folowing command exactly as it is into your terminal or command line
 hostname -I | awk '{print $1}'  
The resulting output will be your server's IP address
For example 192.168.0.1
The web browser should open the Apache2 Ubuntu Default Page.
Configure Your Firewall
At this point, the Apache installation process is complete.
This additional step configures the default UFW firewall to allow traffic
on port 80
First, display the available app profiles on UFW
Type the following into your terminal or command line        
 sudo ufw app list  
The output should be a list of all available application profiles as shown
below List shown varies with kind of apps installed on your computer
Use the following command to allow normal web traffic on port 80
 sudo ufw allow 'Apache'  
Verify the changes by checking the UFW status
 sudo ufw status  
If the status shows inactive. The firewall is not enabled. Use the following
command to enable it
 sudo ufw enable  
Then run
 sudo ufw status  
again. It should show active status as in the 
image above.
If you have other applications or services to allow,make sure you 
configure your firewall to allow traffic.
For example, using the
 sudo ufw allow 'OpenSSH'  
ensures secure encrypted logins over the network. The Apache Service on Ubuntu is now up and running

Apache Configuration
Apache Service Controls
It is helpful to have some level of control over the Apache Service while 
managing it. This is necessary because you'll be reloading and restarting Apache quit frequently as you make configuration changes and test them. You also need to know how to start and stop Apache service as needed. This operation uses the systemctl command with a series of switches Start Apache
 sudo systemctl start apache2.service  

Stop Apache
 sudo systemctl stop apache2.service  
Restart Apache
 sudo systemctl restart apache2.service  
Reload Apache
 sudo systemctl reload apache2.service  
Apache Configuration Files, Directories and Modules
To make content available online, you need to know how to configure  files, directories and modules. Directories
By default, Apache creates a document root directory at
 /var/www/html  

Any files placed into this directory are available to Apache to distribute
over the network.
This is therefore the place where you copy the web page files that you
want to publish.
This is also where you install content management systems such as
WordPress.
Configuration Files
Now that we know that web content is stored in the /var/www/html 
directory, we can create sub directories within this location for each 
different website hosted on your server.
Apache creates log files for any errors it generates in the file 
/var/log/apache2/access.log.
It also creates access logs for its interactions with clients in the file 
/var/log/apache2/access.log
Apache functions through the use of configuration files just like many 
other Linux-based applications
They are located in the /etc/apache2/ directory
A list of other essential directories include:
  • /etc/apache2/apache2.conf - This is the main Apache configuration file and controls everything Apache does on your system.Changes done here affect all the websites hosted on the machine.
  • /etc/apache2/ports.conf - This is the ports configuration file. You can use it to customize the ports Apache monitors. Port 80 is configured for HTTP traffic by default.
  • /etc/apache2/sites-available - This is a storage for Apache virtual host files. A virtual host allows one to run more than website on a single machine.
  • /etc/apache2/sites-enabled - This directory holds websites that are ready to serve clients. The a2ensite command is used on a virtual host file in the sites-available directory to add sites to this location. 
     More details on directories and configuration files are in the Apache Ubuntu Documentation
Modules
These are applications that enhance or expand the functionality of Apache.
You can enable these software modules use the following command
 sudo a2enmod name_of_module  
Disable the module using
 sudo a2dismod name_of_module  

If this guide was helpful or you encountered any problems
please leave a comment below

Comments

  1. What about installing Apache HTTP?

    ReplyDelete
    Replies
    1. It's the same thing. It's called the Apache Web Server which uses HTTP

      Delete
  2. nice job

    looking forward for the next article

    ReplyDelete

Post a Comment

Your input is valued. Please type something....