How To Install Apache on Debian 11

Apache web server is the most popular and widely used web server software out there which is developed by the Apache Software Foundation. The amazing thing about the Apache web server is that it is completely free and is reliable, fast, and secure. Not just this, it also has the ability to meet any need of an environment by making installation of numerous extensions as well as modules.

It is supported on almost all the major operating systems including macOS, Linux distribution, and Windows. We will first install Apache and then uninstall it as well on Debian 11. All this with the help of screenshots and a thorough explanation.

Installation of Apache on Debian 11

Before going to the installation phase let us update our package index which is always the recommendation. We can update the package index using the following command:

$ sudo apt update

After updating let us upgrade the packages with the following command:

Now that we have upgraded and updates our package index, let us start working on installing apache on Debian 11. To achieve the installation of apache on Debian 11, type the following command:

$ sudo apt install apache2

Now that we have installed apache2 let us confirm the installation by typing the following command to check the version that is installed:

$ sudo apache2 -v

We can also confirm the Apache2 installation by accessing the default web page of the Apache2 web server using our Debian 11 system IP address which we can find by executing the following command:

$ ip a

Copy the Ip address shown in the above screenshot and go to your favorite browser and search the Ip address of your server:

You will see the Apache2 Debian Default page as shown above.

Apache Server Managing

Now that we are done with installing the Apache server on Debian 11, let us start managing the service by using the command systemctl. For example, if we want to check the status of the apache server type the following command in your terminal:

$ sudo systemctl status apache2.service

If you see the status as active then congratulations! Your apache is active and running.

Press q to quit. There are other commands to manage our Apache server. One of the commands is to start the server using the following command:

$ sudo systemctl start apache2.service

Just like the above command, we can also stop the apache server service by typing the following command:

$ sudo systemctl stop apache2.service

We can also restart it by changing the above command a little bit:

$ sudo systemctl restart apache2.service

Firewall Configuration

Depending on your system, if it has a firewall then you need to access some ports so that an external person or a user can utilize those ports. we will allow port 80 and port 443 which are for HTTP and HTTPS  respectively. Type the following command in your terminal:

$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp

We can verify the status of the firewall UFW using the following command:

$ sudo ufw status

If the status above does not enable then you can execute the following command to enable it:

$ sudo ufw enable

Uninstall Apache2

There might come a time where you would want to uninstall Apach2 from Debian 11 and you are in luck because today we are going to show you how to uninstall Apach2 from Debian 11.

Go to your terminal and type the following command to see whether apach2 is installed on your computer or not:

$ sudo apache2 -v 

As we can see we have apache 2.4.48 version installed on our system hence to uninstall it, the first step is to target all the apache2 packages and remove them with the help of the following command:

$ sudo apt-get purge apache2 apache2-utils apache2-bin apache2.2-common

Now we will execute the autoremove command just in case any other cleanup is required:

$ sudo apt autoremove

We are done with uninstalling apache2 from Debian 11. To verify the uninstallation, type the following command in your terminal:

$ sudo apache2 -v

When you execute the above command you will see an error which will say  command not found:

Conclusion

As mentioned in the introductory part, the Apache web server is an open-source free service that allows users and developers to share their work on the internet by being reliable, robust, fast as well as secure.

In this article, we taught you how to install and Uninstall the Apache server on Debian 11. We hope that you closely followed the steps and were successful in installing or uninstalling the Apache server.

Subscribe to Our Newsletter
Join our Newsletter and get the latest Linux news and tips
in your inbox for FREE.