In this guide we will see how to install Apache2 Web Server on Debian 10 Buster. The Apache2 web server is one of the most popular web servers. It has numerous robust features. Furthermore, these features include its ability to load various modules dynamically, Moreover, it also supports media element. In addition to above it has the capability to integrate with popular and widely used software.
|Link to the Official Website of Apache2 Web Server|
Here, in this article, we will learn how to install and configure Apache2 web server on our Debian 10 server.
Prerequisites for Installing Apache2 on Debian 10
- Firstly, we will need a machine with Debian 10 preinstalled on it. To install Debian 10 the link to the tutorial is given below:
How to Install Debian 10 Buster
- Next, a stable and fast internet connection for downloading Apache2 and other necessary applications along with their dependencies.
Preparations for installation of Apache2 web server on Debian 10
For our tutorial on ‘How to Install Apache2 on Debian 10’ following prerequisites will be needed.
Create a non-root user with sudo privilege
Now, to create non-root user run the following commands in the terminal window in the given order.
$ sudo adduser <username> [Here replace <username> with your desired username] $ sudo usermod -aG sudo <username> [Here replace <username> with your desired username] $ su - <username> [To test the newly created user]
Install and Configure UFW Firewall
Further, open terminal window in Debian 10 and run the following commands in given order to install and configure the firewall. Although, UFW firewall is pre-installed in Debian by default. But if UFW firewall is not pre-installed then run the following command in the terminal window.
$ sudo apt install ufw
Additionally, if you want to manage the firewall rules for IPV4 and IPV6 then open the following file in your favorite text editor and ensure that the following content is there in the file. Here we are using nano text editor.
$ sudo nano /etc/default/ufw
File content on /etc/default/ufw IPV6=yes
$ sudo ufw enable
Installation of Apache2 Web server on Debian 10 Buster
As a matter of fact, the Apache2 Web Server is part of the default software repositories of Debian 10. Therefore, this enables us to install this web server by using the standard package management utilities of Debian 10 Buster. Next, first update the local package repositories by issuing the following command in the terminal windows in the given order.
$ sudo apt update
Now issue the command to install apache2 web server in the terminal windows.
$ sudo apt install apache2
The above command will first confirm the installation option (Y/n) and then on the affirmative option will automatically install the Apache2 web server and all its dependencies.
Configuring the Firewall
Now it is mandatory to alter the firewall settings so that apache web server is allowed to access the default web ports. If the UFW firewall is configured in such a manner that the outside port access is restricted for apache web server, the apache web servers register itself with UFW during the installation process. This enables some application profiles which may be used to enable or disable access to apache web server through the firewall. We can view the list of such applications by issuing the following command in the terminal window.
$ sudo ufw app list
The output we will get will be as shown below.
Available applications: AIM ………………. WWW WWW Cache WWW Full WWW Secure ……………….
As shown in the output list, the WWW profiles are apache profiles.
- The WWW profile opens port 80 for the web server that supports (normal, unencrypted web traffic.
- The WWW Cache profile opens port 8080, this profile is used for caching and web proxies.
- WWW Full, this profile opens both port 80 that supports normal, unencrypted web traffic and port 443 that supports TLS/SSL encrypted traffic.
- Apache Secure, this profile opens only port 443 that supports TLS/SSL encrypted traffic.
Here we will only need to allow traffic on port 80, therefore issue the following command in the terminal window.
To allow traffic on port 80 through the firewall issue the following command:
$ sudo ufw allow http
To allow traffic on port 443 through the firewall issue the following command:
$ sudo ufw allow https
Now we can verify the change by issuing the following command.
$ sudo ufw status
Status: active To Action From -- ------ ---- 80/tcp ALLOW Anywhere 443/tcp ALLOW Anywhere 80/tcp (v6) ALLOW Anywhere (v6) 443/tcp (v6) ALLOW Anywhere (v6)
The above output indicates that the web server profile is now activated.
Testing of Apache2 Web Server
The installation process of apache2 web server starts the web server after the installation is complete. Therefore the web server will be running.
To check that the Apache web server service is running issue the following command in the terminal windows.
$ sudo systemctl status apache2
The output will be similar to the shown below:
$ sudo systemctl status apache2
apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: Active: active (running) since Sun 2021-08-01 14:30:25 IST; 43min ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 3445 (apache2) Tasks: 55 (limit: 4669) Memory: 10.3M CGroup: /system.slice/apache2.service ├─3445 /usr/sbin/apache2 -k start ├─3447 /usr/sbin/apache2 -k start └─3448 /usr/sbin/apache2 -k start Aug 01 14:30:25 smtp systemd: Starting The Apache HTTP Server... Aug 01 14:30:25 smtp systemd: Started The Apache HTTP Server. lines 1-14/14 (END)
The above output shows that the apache web server service is up and running successfully.
We can also check the status of the web server by typing the local IP in the browser; this will display the apache2 home page in the browser. If you do not know the local IP of your system type the following command in the terminal windows.
hostname –I [This will give the local IP of the system]
Alternatively, typing http://localhost or http://127.0.0.1 in the address bar of the browser will also lead to the default landing page of the apache web server. The default landing page or home page of the apache2 web server is as follows.
Start, Stop, restart, Enable and disable Apache web service
To Start, Stop, restart, Enable and disable Apache web server issue the following command in the terminal window.
sudo systemctl start apache2 sudo systemctl stop apache2 sudo systemctl restart apache2 sudo systemctl reload apache2 sudo systemctl enable apache2 sudo systemctl disable apache2
Finally, we have successfully Installed Apache2 on Debian 10 Buster. Now we can start using our newly installed and configured Apache2 Web Server.