How to Install Apache Web Server on Ubuntu 24.04

Install Apache web server on Ubuntu 24.04

Apache is a free and open-source web server developed by Apache Software Foundation. It is a cross-platform web server and can be installed on Linux, Unix, Windows, and many other operating systems. Apache is known for its stability, security, and flexibility, making it a popular choice for hosting websites and web applications.

Apache can serve static and dynamic content, handle multiple protocols (like HTTP, HTTPS, FTP, etc.), and support various programming languages through modules, such as PHP, Perl, Python, and more. Its modular architecture allows administrators to extend its functionality by adding or removing modules as needed.

In today’s tutorial, we will teach you to install and configure Apache web server on Ubuntu 24.04 LTS. You can also read our article to install Apache web server on Red Hat Enterprise Linux 9.

Prerequisites

Ubuntu 24.04 instance

Root account or a user with sudo privileges

Install Apache Web Server on Ubuntu 24.04

Step 1. Update and upgrade package repository

Before installing packages or software, it is a good practice to update and upgrade package repository index so that you get an updated version.

sudo apt update
sudo apt upgrade

Step 2. Install Apache web server

After updating and upgrading the package repository, the next step is to install Apache web server. Invoke the following command with sudo. When you are prompted press Y to continue the installation.

sudo apt install apache2

This can take several minutes to complete. Sit back and relax.

Configure Apache Web Server on Ubuntu 24.04

Step 1. Allow HTTP and HTTPS from the Firewall

Add HTTP and HTTPS protocols in the firewall to allow web traffic from the server. sudo ufw enable command activates the firewall so that it can start automatically during system reboot.

sudo ufw allow http
sudo ufw allow https
sudo ufw enable

Step 2. Host a Small Web Site

Index.html is the first web page served by Apache when a website is accessed. It is located in /var/www/html/. This path can also be changed from the configuration file. Let’s write a custom message to index file using the cat command.

echo "Welcome to my web server!" > /var/www/html/index.html

Step 3. Test the Configuration

Finally, it is time to test our configuration. Open your favorite browser and type localhost in the address bar.

Uninstall Apache Web Server from Ubuntu 24.04

You can easily uninstall Apache web server from Ubuntu 24.04 using apt package manager. Invoke the command.

sudo apt remove apache2

Conclusion

Thank you for reading the article. Your feedback and criticism is welcome. Keep visiting Linux World.