Introduction

This guide will help you install the Apache web server on Ubuntu Linux 18.04.

Ubuntu 18.04, also known by its codename “Bionic Beaver,” is an LTS (Long-Term Support) release.

Ubuntu 18.04 comes in a couple of different configurations. The desktop configuration uses the Gnome graphical user interface (GUI) and is an excellent environment to learn and use Linux. The server configuration loads the operating system on the server but does not include a graphical user interface. This guide will use the terminal to type commands and should work on either configuration.

Apache Web Server is a software package that turns a computer into an HTTP server. That is, it sends web pages – stored as HTML files – to people on the internet who request them. It is open-source software, which means it can be used and modified freely.

How to Install Apache on Ubuntu 18.04

Prerequisites

  • A system running Ubuntu 18.04 LTS (Bionic Beaver)
  • An internet connection
  • Access to a user account with sudo privileges (sudo allows temporary administrator privileges, once you provide your password)

Tools / Software

  • A command-line utility (Use keyboard shortcut CTRL-ALT-T, or right-click the desktop and left-click Open Terminal).
  • A firewall – the default UFW (Uncomplicated Firewall) in Ubuntu is fine
  • The APT package manager, installed by default in Ubuntu

Apache Installation Procedure On Ubuntu

Before installing new software, it’s a good idea to refresh your local software package database to make sure you are accessing the latest versions. This helps cut down on the time it takes to update after installation, and it also helps prevent zero-day exploits against outdated software.

Open a terminal and type:

sudo apt-get update

Let the package manager finish updating.

Step 1: Install Apache

To install the Apache package on Ubuntu, type the following: sudo apt-get install apache2

Step 2: Verify Installation

To verify Apache was installed correctly,  by open a web browser and type in the address bar:

http://local.server.ip

The web browser should open a page labeled “Apache2 Ubuntu Default Page,” as in the image below:

Apache Ubuntu Default Page

Note: Replace ‘local.server.ip’ with the IP address of your server. If you don’t have it, you can use https://whatismyipaddress.com/ or https://www.whatismyip.com/ to find the IP address of the system you’re working on.

Step 3: Basic Apache Service Functions

When managing a web server, it’s helpful to have some level of control over the service. You’ll probably find yourself reloading or restarting Apache quite frequently, as you make configuration changes and test them. However, it’s also helpful to be able to stop (and start) the Apache service as needed.

This operation uses the systemctl command, with a series of switches:

      • Stop Apache: sudo systemctl stop apache2.service
      • Start Apache: sudo systemctl start apache2.service
      • Restart Apache: sudo systemctl restart apache2.service
      • Reload Apache: sudo systemctl reload apache2.service

Note: It’s best to run only one of these commands at a time.

Step 4: Working with Files, Directories and Modules

Now that you have Apache installed, there are a couple of other things you will need to be aware of to make content available. Most of all, this means dealing with directories and configuration files.

Directories

After installing, Apache by default creates a document root directory at /var/www/html. 

Any HTML files that you place into this directory are available to Apache to distribute over the network. Which means, this is the place where you copy the web page files you want to publish.

Configuration files

Another aspect of Apache is the configuration files. The majority of customized Apache configuration is outside the scope of this guide. The is a vast number of options and add-on modules. However, there are a couple of configuration directories you should be aware of.

1. The first is the list of available sites in /etc/apache2/sites-available.

This location stores configuration files for all of the websites that you want to make available. When Apache is started, it reads this location to get a list of all the websites that it can serve.

If you want to get a look at what one of these configuration files looks like, there should be a default configuration file already here: /etc/apache2/sites-available/000-default.conf.

You can open that with a text editor to see what it looks like. If you’re configuring Apache for websites, you’ll probably need to do some more advanced configuration.

2. The second location is the list of enabled sites: /etc/apache2/sites-enabled

A website might be available in Apache, but not enabled for use.To enable a site use the following command in the terminal and replace ‘mysite.com’ with the name of your website:

sudo a2ensite mysite.com

To disable a site use this command:

sudo a2dissite mysite.com

Modules

If you intend to work with software modules – applications that expand or enhance the functionality of Apache – you can enable them using:

sudo a2enmod name_of_module

To disable the module:

sudo a2dismod name_of_module

Step 5: Configure Your Firewall

Although the installation process is complete, there is one more additional step. It is a good idea to configure your firewall to allow users to connect to your server.

To start configuring the default UFW, you start by displaying the current status. Type the following in a terminal:

sudo ufw status verbose

The terminal should respond by listing its status. Usually, it is set to deny incoming traffic, and allow outgoing.

Use the following command to allow normal web traffic:

sudo ufw allow http

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 ssh command will enable secure, encrypted logins over the network.

For more information on configuring your firewall, Ubuntu has excellent documentation.

Glossary

      • UFW – Uncomplicated Firewall, a software application that blocks network traffic (usually for security)
      • SSH – Secure Shell, used for encrypted logins over a network
      • APT – Ubuntu’s default package manager, used for installing and updating software packages
      • GUI – Graphical User Interface – the “point and click” interface of the operating system

Conclusion

If you’ve followed this tutorial, now you know how to install Apache Web Services on Ubuntu.

Apache is very widely used and is highly customizable through add-on modules such as MySQL.