How to Install Apache2 on AWS EC2 Instance Ubuntu 20.04/22.04

How to Install Apache2 on AWS EC2 Instance Ubuntu 20.04/22.04

Install Apache 2 on AWS ec2 instance ubuntu. Through this tutorial, we will show you how to install apache 2 web server on aws ec2 instance ubuntu linux.

Nota that, The Apache HTTP web server is the most widely-used web server in the world. It provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software.

Install Apache2 on AWS EC2 Instance Linux Ubuntu 20.04/22.04

Steps to install and configure Apache 2 on AWS ec2 instance linux ubuntu 20.04/22.04:

  • Install Apache2 on AWS EC2 Instance Ubuntu 20.04/22.04
  • Setup Firewall with UFW on Ubuntu
  • Managing the Apache Process

Install Apache2 on AWS EC2 Instance Ubuntu 20.04/22.04

Steps to install apache2 on aws ec2 instance ubuntu 20.04/22.04:

Step 1: Connect Your AWS EC2 Intance from SSH

First of all, you need to connect your aws ec2 instance from ssh. If you are new to connect aws ec2 instance with windows, ubuntu and mac system. So you can read this tutorial “How to Connect to ec2 Instance From Putty and SSH Terminal” to connect your ec2 instance from ssh.

Step 2: Update Ubuntu System Repositories

In this step, you need to download the latest version of the software by first updating the local package index of Ubuntu repositories. So, start your ssh terminal and type the below given command:

sudo apt update

Step 3: Install Apache 2

In this step, use the below given command to install apache 2 into your ubuntu web server. So, open ssh terminal again and run this sudo command to install apache web server on aws ec2 instance:

sudo apt install apache2

Note that, on running installation of apache 2 web server on aws ec2 instance. The prompt box will be open with a “Y/N” option to continue the installation.

Please enter Y, after which the installation process will begin.

Step 4: Verify the Apache installation

Installing Apache2 web server on your Ubuntu 20.04 EC2 instance is completed. So, open your ssh terminal and type the below command to check the Apache 2 is installed or not on our Ubuntu 20.04 aws EC2 instance:

apache2 -version

Congratulation!!, You have successfully installed the Apache 2 web server on AWS ec2 instance.

If you want to access it from outside. So, you need to update firewall settings on your apache 2 web server on your Ubuntu 20.04 EC2 instance.

Setup Firewall with UFW on Ubuntu

Steps to setup firewall with ufw on ubuntu:

Step 1: List the UFW application profiles

In this step, open your terminal ssh and type the following command to list such available firewall ufw applications,:

sudo ufw app list

Then you will see a list of the application profiles:

OutputAvailable applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

As indicated by the output, there are three profiles available for Apache:

  • Apache: This profile opens only port 80 (normal, unencrypted web traffic)
  • Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)

Step 2: Allow Apache Full on UFW

In this step, you need to allow Apache Full on UFW will open port 80 and 443 for network traffic, while providing maximum security to the server. So, use the below given UFW command to allow Apache Full through the following command:

sudo ufw allow 'Apache Full'

You can verify the change by typing:

sudo ufw status

The output will provide a list of allowed HTTP traffic:

OutputStatus: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
Apache                     ALLOW       Anywhere                
OpenSSH (v6)               ALLOW       Anywhere (v6)             
Apache (v6)                ALLOW       Anywhere (v6)

Step 3: Verify that the Apache service is running

sudo systemctl status apache2

Finally, open your browser and type your AWS ec2 instance IP address. And, it will be looks like the Apache 2 page in the following picture:

install apache 2 web server on amazon ec2
install apache 2 web server on amazon ec2

Managing the Apache Process

Commands to manage apache process:

To stop your web server, type:

sudo systemctl stop apache2

To start the web server when it is stopped, type:

sudo systemctl start apache2

To stop and then start the service again, type:

sudo systemctl restart apache2

If you are simply making configuration changes, Apache can often reload without dropping connections. To do this, use this command:

sudo systemctl reload apache2

By default, Apache is configured to start automatically when the server boots. If this is not what you want, disable this behavior by typing:

sudo systemctl disable apache2

To re-enable the service to start up at boot, type:

sudo systemctl enable apache2

Apache should now start automatically when the server boots again.

Conclusion

Install apache on AWS ec2 instance ubuntu tutorial, You have learned how to install apache 2 on aws ec2 ubuntu.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *