How to install Apache2 in AWS Ec2 Ubuntu 22.0 | 20.04 Linux

It doesn’t matter if you are on Ubuntu 20.04 or 22.04, the steps and commands to install the Apache web server on AWS EC2 running an Ubuntu instance will be the same.

Apache is one of the most reliable web server software powering millions of hosting servers to run various types of websites. Apache2 is the second version of the Apache HTTP server and is available for all the major operating systems such – as Windows, macOS, and Linux. One of the reasons, why the Apache web server is still active and used by millions of people around the globe for a very long time is its support for various programming languages such as PHP, Perl, and Python; and its capability to serve static and dynamic web pages.

Apache2 is also highly configurable, therefore developers can use it to customize the server’s behavior and performance to meet their specific needs.

Installing the Apache Web server on AWS Ec2 running an Ubuntu instance is not different from the Ubuntu distro running on our system.

Here are the steps to follow:

1. Access Ubuntu Ec2 Instance Shell

If you already have installed the Ubuntu Linux on AWS Ec2 Instance then connect it via SSH or web console to issue the command.

However, those who have not yet created Ubuntu Ec2 can see our article’s first – Step by step tutorial to launch Ubuntu on EC2.

After that follow this tutorial.

2. Run Apt Update

As you have the access to the command line using SSH or the web console of Ubuntu, first, run the system update command. So, that we have the latest security and package updates.

sudo apt update && sudo apt upgrade -y

3. Installing Apache2 on AWS Ubuntu Ec2

With the finishing of the Update command, we will execute the APT command to download and install the Apache web server on our Ubuntu. And for this, you don’t need to add any additional repository.

sudo apt install apache2

4. Check Apache Service Status

Now, we know that Apache is on our system but to confirm whether its service is running or not in the background, use:

sudo systemctl status apache2

The green color “Active” shows that the web server is running perfectly.

Check Apache2 Service status on Ubuntu Ec2

5. Access the default Web page

Let’s also access the default web page of the Apache web server to confirm further and see if it is not throwing any HTTP error while accessing the test page.

For that, you can enter the domain name associated with your Instance or copy the public IP address of your Ubuntu Ec2 Instace which you can easily get on the Ec2 Instance page.

Copy the Ubuntu Ec2 Instance IP address

Copy the address and paste it into your browser URL as- http://server-ip-address.

For example:

http://65.0.199.32
Apache Test Page

6. Commands to restart and Stop Apache web server

In the future, if you want to restart the Apache web server on Ubuntu AWS Ec2 then for that here is the command:

Restart

sudo systemctl restart apache2

Similarly to STOP:

sudo systemctl stop apache2

To refresh Apache, if some settings are changes related to it:

sudo systemctl reload apache2

7. Uninstallation of Apache2 From AWS Ubuntu

Tomorrow, if there is no need for the web server and you want to completely remove Apache2 from Ubuntu AWS Ec2 then for that here is the command to follow:

sudo systemctl stop apache2
sudo apt autoremove --purge apache2

Other Articles:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.