How to Install Apache on Linux?

Installing the Apache HTTP Server on a Linux system is a straightforward process that enables you to host websites and web applications. This guide provides a quick overview of the installation steps for the most popular Linux distributions, specifically focusing on Ubuntu/Debian-based systems using the apt package manager and CentOS/RHEL-based systems using yum or dnf. By following these platform-specific commands, configuring your firewall, and managing the system services, you can have a secure, fully functional web server running in just a few minutes.

Installing Apache on Ubuntu and Debian

Ubuntu and Debian systems use the Advanced Package Tool (apt) to manage software. Before installing any new packages, it is best practice to update your local package index to ensure you download the latest version available.

Installing Apache on CentOS, RHEL, and Fedora

Red Hat-based distributions use yum or dnf as their package managers. On these systems, the Apache package is known as httpd rather than apache2.

Configuring the Firewall

To allow external traffic to reach your new web server, you must open the appropriate web ports in your system’s firewall. Standard web traffic uses port 80 (HTTP), while secure traffic uses port 443 (HTTPS).

Testing Your Web Server

With the installation complete and the firewall configured, you can test if Apache is running correctly. Open a web browser on a device connected to the same network and type your Linux server’s IP address into the address bar. If you are testing directly on the server, you can use http://localhost. If successful, you will see the default Apache welcome page, confirming that the web server is properly installed and ready to host your content.