In this tutorial we will learn how to install apache2 web server on Ubuntu 20.04. We will also learn how to install and configure UFW firewall on Ubuntu 20.04. The Apache2 web server is one of the most popular web servers around. It has numerous robust features. Moreover, these features include its ability to load various modules dynamically. It also supports media element. In addition to above, it has the capability to integrate with many popular and widely used software. In this article, we will learn how to install Apache2 web server on our Ubuntu 20.04 LTS – Focal Fossa. We will also learn how to configure the Web Server on Ubuntu 20.04.
|How to Install Ubuntu 20.04 LTS – Focal Fossa|
Preparations for installation of Apache2 on Ubuntu 20.04
Create a non-root user with sudo privilege on Ubuntu 20.04
To create this user run the following commands in the terminal window in the given order.
sudo adduser <username> [your desired username]
sudo usermod -aG sudo <username> [your desired username]
su - <username> [Test newly created user]
Install and Configure UFW Firewall on Ubuntu 20.04
Open terminal windows in Ubuntu 20.04. Now execute the following commands in given order to install and configure the firewall. Normally, the UFW firewall is pre-installed in Ubuntu. If it is not pre-installed then run the following command in the terminal window.
sudo apt install ufw
Further more, if you want to manage the firewall rules for IPV4 and IPV6. Then open the following file in your favorite text editor. This is important to ensure that the following content is there in the file. Here I am using nano text editor.
sudo nano /etc/default/ufw
|File content on /etc/default/ufw|
In addition to above, setup the default policies by running the following commands in the terminal window.
sudo ufw default deny incoming
sudo ufw default allow outgoing
Further, to allow ssh connection, run the following command in the terminal window.
sudo ufw allow ssh
Also, allow any specific port through the UFW firewall by executing the following command in the terminal window.
sudo ufw allow <specific port number>
To enable or disable the UFW firewall, run the following command in the terminal window.
sudo ufw enable
sudo ufw disable
Install Apache2 Web Server
As we know that the apache2 Web Server is part of the default software repositories of Ubuntu 20.04. Therefore, this enables us to install the apache web server by using the standard package management utilities of Ubuntu 20.04. Now, first update the local package repositories by issuing the following command in the terminal window.
Now issue the following 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). Then on the affirmative selection of the option, it will automatically install the apache2 web server and all its dependencies.
|How to Install LAMP on Ubuntu 20.04 With Screenshots|
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. Then 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.
As shown in the output list, there are three profiles available for the apache web server:
- Apache profile opens port 80 for the web server. This profile supports normal, unencrypted web traffic.
- Apache Full profile opens both port 80 and port 443. This profile supports both normal, unencrypted web traffic on port 80 and port 443 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.
sudo ufw allow 'Apache'
Now we can verify the change by issuing the following command.
sudo ufw status
OpenSSH ALLOW Anywhere
Apache ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Apache (v6) ALLOW Anywhere (v6)
The above output shows 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 completion of the installation. 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
|apache2.service – The Apache HTTP Server|
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese>
Active: active (running) since Thu 2021-07-22 19:05:18 IST; 1h 21min ago
Process: 687 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUC>
Main PID: 841 (apache2)
Tasks: 55 (limit: 4652)
├─841 /usr/sbin/apache2 -k start ├─842 /usr/sbin/apache2 -k start └─843 /usr/sbin/apache2 -k start
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. This will give the local IP of the system.
sudo hostname –I
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 looks like as given below.
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 windows
sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2
sudo systemctl reload apache2
sudo systemctl enable apache2
sudo systemctl disable apache2
Now we can start using our newly installed and configured apache2 Web Server on Ubuntu 20.04.
|How to Install PhpMyAdmin on Ubuntu 20.04|