How to Install Apache on Ubuntu 22.04

Apache is a freely available popular open-source web server. It is safe, quick, and more reliable as compared to its competitors. The Apache License 2.0 was used to release Apache. With the help of extensions and modules, it operates on different environments such as OpenVMS, Unix, Windows, and Linux distributions, including Ubuntu 22.04.

We will demonstrate the way to install and uninstall Apache in this guide.

Apache Installation on Ubuntu 22.04

To install Apache on Ubuntu 22.04, follow the given steps.

Step 1: Update system package

First, open the terminal using “CTRL+ALT+T” and run provided command to update system packages:

$ sudo apt update

Step 2: Install Apache

In the next step, install Apache directly from the Ubuntu 22.04 repository:

$ sudo apt install apache2 -y

Step 3: Enable Firewall

After installing Apache, enable the Firewall settings:

$ sudo ufw enable 

Check the list of available services:

$ sudo ufw app list

Step 4: Enable Apache

Use “Apache Full” to enable Apache on port “80” and port “443”:

$ sudo ufw allow 'Apache Full'

Now, view the port status by utilizing the given command:

$ sudo ufw status

Step 5: Check Apache service status

To check the status of the Apache services, execute the command shown below:

$ systemctl status apache2

Lastly, visit the “localhost” on the web browser and verify if Apache is accessible or not:

As you can see from the above-given output, Apache is successfully installed and activated on Ubuntu 22.04.

Apache uninstallation from Ubuntu 22.04

To uninstall Apache from Ubuntu 22.04, follow the steps given below.

Step 1: Stop Apache service

First, stop the Apache services:

$ sudo service apache2 stop

Step 2: Uninstall Apache

Uninstall the Apache from Ubuntu 22.04:

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

Step 3: Remove Apache directory

To remove the Apache directory from Ubuntu 22.04, execute the given command:

$ sudo rm -rf /etc/apache2

We have demonstrated the procedure for Apache installation and uninstallation on Ubuntu 22.04.

Conclusion

To install the Apache web server on Ubuntu 22.04, first, update the system packages. Then install Apache using the “$ sudo apt install apache2 -y” command on the terminal. After installation, enable the Firewall, Activate Apache services, and surf “localhost” on the web browser to access Apache. This guide discussed the method to install and remove Apache from Ubuntu 22.04.