Sign In
Sign In

Installing and Configuring Apache on Ubuntu 22.04

Installing and Configuring Apache on Ubuntu 22.04
Hostman Team
Technical writer
Ubuntu Apache
24.11.2023
Reading time: 5 min

The term web server refers to both physical machines and specialized software. In software terms, a web server is a program that implements server logic in a client-server architecture: it accepts HTTP requests from clients and returns the appropriate responses.

There are a large number of different web servers that offer their users additional functionality. The user can choose the most suitable solution for their tasks depending on their needs.

The most common web servers in 2023 are Nginx and Apache. In this article, we will describe how to install and configure Apache on Ubuntu 22.04 operating system.

What is Apache

Apache HTTP Server, or simply Apache, is a free and open-source cross-platform web server. It was developed in 1995 by a group of developers to address the shortcomings of the then-popular NCSA HTTPd web server.

NCSA HTTPd was one of the first web servers, developed in 1993 at NCSA, University of Illinois. It was distributed for free and allowed users to host their first web pages. Still, NCSA HTTPd had limited features compared to modern web servers and some other shortcomings that eventually led to the introduction of Apache.

A year after its release, Apache gained popularity among hosting companies and developers due to its new functionality and cross-platform nature. In 2005, about 70% of all servers on the Internet were running Apache. Today, this figure is around 20%, and Apache's main competitor is Nginx.

Apache consists of two main components: kernel and modules. The kernel performs basic web server functions: it processes configuration files, performs HTTP-related actions, and loads additional modules. Modules allow you to extend the basic functionality of the kernel: support for new programming languages, user authorization, increased security, etc. The Apache team works exclusively on the kernel.

Overall, the pros of Apache include:

  • Free software;

  • Customization: Apache web server can be easily customized for specific goals and tasks thanks to many add-ons and its open-source code.

  • Large community;

  • Cross-platform;

  • Good level of performance and security.

As to the cons:

  • Resource demanding, mainly when handling a large number of concurrent requests;

  • Limited multithreading: Apache uses multiprocessing technology, placing each connection in a separate thread. The number of such threads is limited, which negatively affects the number of requests;

  • Difficult to configure due to the large number of settings.

Installing Apache

There are several steps to install Apache:

Step 1: Update apt package indexes

Before installing any software on Ubuntu, the first thing to do is to update the package indexes. It will ensure that the repository has the latest packages available for installation.

Run the following command:

sudo apt update

Step 2: Install the Apache web server

Installing the Apache web server on Ubuntu is a simple process that involves running a single command and rebooting the system. 

sudo apt install apache2

After that, reboot the system.

Step 3: Start Apache and launch it at boot

To start the Apache service, run this command:

sudo systemctl start apache2

This command will have to be run every time you start the server. To avoid this, set Apache to start at boot:

sudo systemctl enable apache2

Step 4: Check Apache server installation

Let's check the status of the Apache service to make sure the installation was successful:

service apache2 status

F38fc8f0 34d2 4607 Babd 8d0b49a6c6e1

Configuring firewall

Now that you have installed Apache on Ubuntu, allow external connections through the UFW firewall.

UFW (Uncomplicated Firewall) is a command line interface for the iptables Linux firewall. It makes firewall rule management easier and more accessible to newbies. UFW allows you to easily configure firewall rules such as opening or closing ports, blocking or allowing network access, etc.

-

You can skip this section if your server is not running UFW or does not have a firewall installed. But we recommend using a firewall to keep your device secure.

With a firewall enabled, you may find that you cannot connect to the Apache server from a remote device because the ports that Apache uses are closed by default. These are port 80 (HTTP) and port 443 (HTTPS). Even if you plan to work only with HTTPS connections, it's a good idea to allow connections to port 80 so that you can redirect them to HTTPS.

First of all, let's make sure that the UFW firewall is enabled:

sudo ufw status

We should see the Active status. If not, start the ufw service with the following command:

sudo ufw enable

To allow access to port 80, use the following command in the terminal:

sudo ufw allow 80

Now, to use HTTPS, you also need to open port 443. Port 443 is the port that HTTPS runs on by default. So, if you visit a site that uses the "https://" protocol, your web browser will use this port.

You can enable this port with this command:

sudo ufw allow 443

Accessing your website

Now that you have installed the Apache web server on Ubuntu and opened connections in the firewall let's try to access it.

If you plan to connect from a remote device, the first thing you need to do is find out the IP address of the Apache server. There are several ways to find this out.

The easiest way is to use the hostname command with the -I option. The command will return a list of IP addresses assigned to your device.

hostname -I

For example, our test server only has a local IP address:

192.168.0.215

This is the address you need to go to in a browser. If you are accessing directly from your Ubuntu server, you can use 127.0.0.1 or localhost instead.

You should see a page similar to the one below.

Ab625e3b A845 4282 8fd7 Ff61c0a4bd6c

This indicates that you have successfully started Apache on Ubuntu.

Conclusion

This material covered installing Apache on Ubuntu 22.04, configuring the firewall, and getting the server up and running. When developing a website or web application, these steps will be the first steps towards a finished product. You can rent a cloud server for your project at Hostman.

Ubuntu Apache
24.11.2023
Reading time: 5 min

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start
Email us