How to Install Apache Web Server on Linux Step by Step

Learn step-by-step commands to install Apache web servers on Linux such as Debian, Ubuntu, RedHat, CentOS, Almalinux, Rocky, Linux Mint, OpenSUSE, Amazon Linux, and more…

Web servers are an important part of the Internet, but also provide useful services even for local networks. Setting up a web server with Apache is not a difficult task, yet here we learn how to do it…

However, before going any further, let’s talk a bit about the Apache web server.

What is the function of a web server?

The primary use of web servers is to deliver HTML and image content over HTTP or HTTPS protocols. Whenever we enter a web address into our browser to open a website or HTML page, the browser requests this from the web server on port 80 (“http://”) or port 443 (“https:// “), if the page is present there, the same will be displayed to you. Well, web servers and browsers are key Internet technologies. Both provide infrastructure for retrieving information, storing data, shopping online, and communicating on social media.

In terms of browsers, we have the popular Chrome, FireFox, Edge, Brave, Tor, etc. When it comes to web server software platforms, we also have many popular names like IIS, Apache, LightSpeed, Nginx, etc. However, thThe Apache HTTP server is one of the most widely used web servers. It’s been around for over 20 years, and many of the configuration examples refer to Apache. Although, many web application users prefer Nginx over Apache due to its lower PC resource consumption and ability to serve a large number of users. While others prefer to use both, Apache as the web server with Nginx as the reverse proxy. The advantage is that the load can be distributed between the two servers and the overall performance can be increased. NGINX vs Apache: Comparison of Web Servers to Host Your Website

Well Apache web server mostly installed together with other tools because in today’s world we will mostly not use simple static html files on web server but use CMS or another web application. Such as WordPress, Joomla Nextcloud, etc. to create dynamic websites. And for this, the web server needs scripting languages, usually PHP, Perl or Python. Basically, the web server can start any external program, regardless of the programming language used, whose HTML or text output it passes to the client (browser).

Learn how to install WordPress on Ubuntu Linux.

Steps to Install Apache Web Server on Linux

The commands given here can be followed on most Linuxes, regardless of their versions.

On Ubuntu and Debian Linux

The commands presented in this tutorial will work on all Debian and Ubuntu based systems, such as Elementary, Linux Mint, MX Linux, POP OS, etc. to install the Apache web server

Step 1: Connect to the Linux server

First access the command terminal of your Linux server where you want to install the Apache web server. Those using a cloud or a remote server can use SSH to log in remotely.

Step 2: Run System Update

The second step is to run the system update command which will install all available updates on your system. It will also refresh the APT package manager cache.

sudo apt update && sudo apt upgrade

Step 3: Install Apache on Linux

Then use APT package manager and install Apache web server on your Linux. The best thing that we don’t need a third party repository to install it. All packages are available using the default Linux system repository.

sudo apt install apache2

Step 4: Activate and verify the service

Although the Apache web server service is automatically set by the system to start with boot, let’s run the given command to confirm the same:

sudo systemctl enable --now apache2

To check if the service is working perfectly or not, run:

systemctl status apache2 --no-pager -l

Production:

On RedHat, Fedora, Amalinux, Rocky, CentOS, Oracle, Amazon Linux

Well, although Ubuntu and Debian are also Linux, the command to install Apache web server on RHEL based Linux will be different. So, if your Linux is based on RedHat then here are the commands to follow:

Step 1: Access the terminal

The very first thing we want to access is the command line. Therefore, access the terminal server directly or use remote SSH.

Step 2: Update Linux

Just like we did for Ubuntu, we also run the system update command first for RHEL-based Linux systems. Here is the one to follow:

sudo dnf update && sudo dnf upgrade

Step 3: Install Httpd or Apache on Linux

In Redhat-based Linux, Apache is known as HTTPD, so here we’ll use RHEL systems’ DNF package manager to install the web server.

sudo dnf install httpd

Step 4: Start and check status

To enable, start, and check the status of the Apache web server service after installation, run the given commands:

sudo systemctl enable --now httpd

To check the status:

systemctl status httpd --no-pager -l

Command to stop and restart apache

Well, if you want to stop, reload and restart the Apache web server in the future, here are the commands to use:

To recharge

On Ubuntu and Debian systems:

sudo systemctl reload apache2

On Redhat-based systems:

sudo systemctl reload httpd

Restart

On Ubuntu and Debian systems:

sudo systemctl restart apache2

On Redhat-based systems:

sudo systemctl restart httpd

Stop

On Ubuntu and Debian systems:

sudo systemctl stop apache2

On Redhat-based systems:

sudo systemctl stop httpd

Uninstall or completely remove

If you have misconfigured or no longer want the Apache web server on your Linux system, here are the commands to remove it completely.

For Ubuntu and Debian based systems:

sudo apt autoremove --purge apache2

For Redhat-based systems:

sudo dnf remove httpd

Other Items:

How to Install Apache on Almalinux 8 / Rocky Linux 8
How to install WordPress on AlmaLinux 8
Install the NextCloud server on AlmaLinux 8
Configure Nginx as Reverse Proxy for Apache on Ubuntu
How to install phpMyAdmin with Apache on Ubuntu Linux