Home » Install APACHE server on AWS EC2 Instance

Install APACHE server on AWS EC2 Instance

Launch an EC2 instance and install Apache Webserver in just two steps

Apache is a very powerful and flexible web server that works across a large variety of platforms and environments.  It is open source and therefore very popular. The modular design of Apache is also an important factor behind its popularity. It still rules the web world with the largest share among web servers followed by NGINX. Apache is feature rich and serves users well across various platforms. New features can be added with the help of modules to extend its functionality.

Installing Apache on AWS EC2 instance with Amazon Linux 2 is very easy and can be completed in just a few steps. First of all, you will need to create an instance and once the instance is ready, you can install the Apache httpd server on it in only two to three steps.

Let’s start with the creation of an EC2 instance. Login to your AWS account and go to EC2 dashboard. You can search for EC2 in the search box at the top. Once you are inside the EC2 dashboard, click on Launch instances button on the right at the top.

Give your instance a name like example-webserver. In the Application and OS images section, you can go with the default selection, which is Amazon Linux or select another OS like Ubuntu or Debian if you like.

Lets continue with Amazon Linux 2.

Select an instance type. For testing purposes, you can go with a free tier eligible instance like t2.micro. In the key pair section, select create a new key pair. Give the new key pair a name and then move on to create it.

The next section is Network settings and you will need to create a security group that will allow SSH traffic as well as http and https traffic from different ports.

Open the EC2 dashboard in another tab and open security groups. Create a new security group and you need to add a few inbound rules so that you can safely access the instance through SSH. Otherwise, the SSH connection to your instance will fail. We need to open a few ports including 22, 80 and 443. Let’s first allow SSH traffic on port 22. Under type, select SSH and it will automatically fill the Protocol and port range. For sources select 0.0.0.0/0. Allow HTTP and HTTPS traffic also. At last, allow all traffic from your own ip. Check the image below.

Now that you have created a security group, return to the page where we are creating our EC2 instance. In the network settings section, click on Select existing security group. If the security group is still not visible in the drop down menu, then click on the refresh button to the right of the box. Select the security group, you just created. Now, the heavy work is behind us.

The next section is to configure storage. You can increase the storage size based on your need. Leave the advanced details section as it is and click on launch instance button on the right at the bottom. Your instance will be ready for connection in a few minutes only.

Go back to the EC 2 dashboard, where you can see the newly created instance. Wait a few minutes, and once the instance is ready and in running state, you can connect with it. Click on the instance and then click on the connect button. It will open the terminal. Now, that your instance is ready, the next step is the installation of the Apache httpd server, before you can bring your website online.

There are just two main steps in the installation of the Apache httpd server. Before installing the Apache web server, install the available updates.

$ sudo yum update -y

For Ubuntu – $ sudo apt update -y

Next, you can install the httpd or apache 2 server with the following command:

$ sudo yum install -y httpd

For Ubuntu $ sudo apt install -y apache2

The process takes a few minutes and once the server is installed, you will receive the process completed message. Apache httpd server can be installed on Amazon Linux (EC2 instance) with these two simple commands. You will only need to start and enable the Apache server now, which can be done with the following commands:

$ sudo systemctl start httpd

$ sudo systemctl enable httpd

On Ubuntu :

$sudo systemctl start apache2

$ sudo systemctl enable apache2

To check if the server is working as expected (Apache httpd server status on Amazon Linux2), you can run the following command:

$ sudo systemctl status httpd

For Ubuntu run:

$ sudo systemctl status apache2

So, this was how you can easily install the Apache server on an AWS EC2 instance. To run a simple website, you will just need to create a vhost file, get the ssl and upload your website in the root folder. However, if you are planning to use wordpress, you will also need to install WordPress, php, and the mysql or mariadb database before you can bring your site online. Following the above process, you can set up an Apache web server and bring a simple static website online in minutes.

Here is how the output looks at each stage when you are installing the Apache web server on Amazon Linux 2.

Stage 0: Run updates

$sudo yum update -y

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd

amzn2-core                                                                                                                 | 3.7 kB  00:00:00    

Resolving Dependencies

–> Running transaction check

—> Package ec2-hibinit-agent.noarch 0:1.0.2-3.amzn2 will be updated

—> Package ec2-hibinit-agent.noarch 0:1.0.2-4.amzn2 will be an update

—> Package rsyslog.x86_64 0:8.24.0-57.amzn2.2.0.1 will be updated

—> Package rsyslog.x86_64 0:8.24.0-57.amzn2.2.0.2 will be an update

—> Package tzdata.noarch 0:2022f-1.amzn2.0.1 will be updated

—> Package tzdata.noarch 0:2022g-1.amzn2.0.2 will be an update

–> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================

 Package                           Arch                   Version                                Repository                  Size

==================================================================================================================================================

Updating:

 ec2-hibinit-agent                 noarch                 1.0.2-4.amzn2                          amzn2-core                  14 k

 rsyslog                          x86_64                 8.24.0-57.amzn2.2.0.2                  amzn2-core                 619 k

 tzdata                            noarch                 2022g-1.amzn2.0.2                      amzn2-core                 480 k

Transaction Summary

==================================================================================================================================================

Upgrade  3 Packages

Total download size: 1.1 M

Downloading packages:

Delta RPMs disabled because /usr/bin/applydeltarpm not installed.

(1/3): ec2-hibinit-agent-1.0.2-4.amzn2.noarch.rpm                                                                     |  14 kB  00:00:00    

(2/3): tzdata-2022g-1.amzn2.0.2.noarch.rpm                                                                             | 480 kB  00:00:00    

(3/3): rsyslog-8.24.0-57.amzn2.2.0.2.x86_64.rpm                                                                        | 619 kB  00:00:00    

————————————————————————————————————————————————–

Total                                                                                                         3.5 MB/s | 1.1 MB  00:00:00    

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Updating   : rsyslog-8.24.0-57.amzn2.2.0.2.x86_64                                                                                       1/6

  Updating   : ec2-hibinit-agent-1.0.2-4.amzn2.noarch                                                                                     2/6

  Updating   : tzdata-2022g-1.amzn2.0.2.noarch                                                                                            3/6

  Cleanup : ec2-hibinit-agent-1.0.2-3.amzn2.noarch                                                                                     4/6

  Cleanup : tzdata-2022f-1.amzn2.0.1.noarch                                                                                            5/6

  Cleanup : rsyslog-8.24.0-57.amzn2.2.0.1.x86_64                                                                                       6/6

  Verifying  : tzdata-2022g-1.amzn2.0.2.noarch                                                                                           1/6

  Verifying  : ec2-hibinit-agent-1.0.2-4.amzn2.noarch                                                                                     2/6

  Verifying  : rsyslog-8.24.0-57.amzn2.2.0.2.x86_64                                                                                      3/6

  Verifying  : tzdata-2022f-1.amzn2.0.1.noarch                                                                                            4/6

  Verifying  : ec2-hibinit-agent-1.0.2-3.amzn2.noarch                                                                                    5/6

  Verifying  : rsyslog-8.24.0-57.amzn2.2.0.1.x86_64                                                                                       6/6

Updated:

  ec2-hibinit-agent.noarch 0:1.0.2-4.amzn2       rsyslog.x86_64 0:8.24.0-57.amzn2.2.0.2      tzdata.noarch 0:2022g-1.amzn2.0.2         

Complete!

Stage 1: Apache httpd server installation

[ec2-user@ip-xx-xx-xx-xx ~]$ sudo yum install -y httpd

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd

Resolving Dependencies

–> Running transaction check

—> Package httpd.x86_64 0:2.4.55-1.amzn2 will be installed

–> Processing Dependency: httpd-tools = 2.4.55-1.amzn2 for package: httpd-2.4.55-1.amzn2.x86_64

–> Processing Dependency: httpd-filesystem = 2.4.55-1.amzn2 for package: httpd-2.4.55-1.amzn2.x86_64

–> Processing Dependency: system-logos-httpd for package: httpd-2.4.55-1.amzn2.x86_64

–> Processing Dependency: mod_http2 for package: httpd-2.4.55-1.amzn2.x86_64

–> Processing Dependency: httpd-filesystem for package: httpd-2.4.55-1.amzn2.x86_64

–> Processing Dependency: /etc/mime.types for package: httpd-2.4.55-1.amzn2.x86_64

–> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.55-1.amzn2.x86_64

–> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.55-1.amzn2.x86_64

–> Running transaction check —> Package apr.x86_64 0:1.7.2-1.amzn2 will be installed

—> Package apr-util.x86_64 0:1.6.3-1.amzn2.0.1 will be installed

–> Processing Dependency: apr-util-bdb(x86-64) = 1.6.3-1.amzn2.0.1 for package: apr-util-1.6.3-1.amzn2.0.1.x86_64

—> Package generic-logos-httpd.noarch 0:18.0.0-4.amzn2 will be installed

—> Package httpd-filesystem.noarch 0:2.4.55-1.amzn2 will be installed

—> Package httpd-tools.x86_64 0:2.4.55-1.amzn2 will be installed

—> Package mailcap.noarch 0:2.1.41-2.amzn2 will be installed

—> Package mod_http2.x86_64 0:1.15.19-1.amzn2.0.1 will be installed

–> Running transaction check

—> Package apr-util-bdb.x86_64 0:1.6.3-1.amzn2.0.1 will be installed

–> Finished Dependency Resolution

Dependencies Resolved ==================================================================================================================================================  Package                             Arch                   Version                              Repository                  Size ================================================================================================================================================== Installing:  httpd                               x86_64                 2.4.55-1.amzn2                       amzn2-core                 1.4 M Installing for dependencies:  apr                                 x86_64                 1.7.2-1.amzn2                        amzn2-core                 130 k  apr-util                            x86_64                 1.6.3-1.amzn2.0.1                    amzn2-core                     101 k  apr-util-bdb                        x86_64                 1.6.3-1.amzn2.0.1                    amzn2-core                  22 k  generic-logos-httpd                 noarch                 18.0.0-4.amzn2                           amzn2-core                  19 k  httpd-filesystem                    noarch                 2.4.55-1.amzn2                       amzn2-core                  24 k  httpd-tools                         x86_64                     2.4.55-1.amzn2                       amzn2-core                  88 k  mailcap                             noarch                 2.1.41-2.amzn2                       amzn2-core                  31 k  mod_http2                               x86_64                 1.15.19-1.amzn2.0.1                  amzn2-core                 149 k Transaction Summary ================================================================================================================================================== Install  1 Package (+8 Dependent packages) Total download size: 1.9 M Installed size: 5.2 M Downloading packages: (1/9): apr-1.7.2-1.amzn2.x86_64.rpm                                                                                   | 130 kB  00:00:00 (2/9): apr-util-bdb-1.6.3-1.amzn2.0.1.x86_64.rpm                                                                       |  22 kB  00:00:00 (3/9): generic-logos-httpd-18.0.0-4.amzn2.noarch.rpm                                                                   |  19 kB  00:00:00 (4/9): apr-util-1.6.3-1.amzn2.0.1.x86_64.rpm                                                                           | 101 kB  00:00:00 (5/9): httpd-2.4.55-1.amzn2.x86_64.rpm                                                                                 | 1.4 MB  00:00:00 (6/9): httpd-filesystem-2.4.55-1.amzn2.noarch.rpm                                                                      |  24 kB  00:00:00 (7/9): mailcap-2.1.41-2.amzn2.noarch.rpm                                                                               |  31 kB  00:00:00 (8/9): httpd-tools-2.4.55-1.amzn2.x86_64.rpm                                                                           |  88 kB  00:00:00 (9/9): mod_http2-1.15.19-1.amzn2.0.1.x86_64.rpm                                                                        | 149 kB  00:00:00  ————————————————————————————————————————————————– Total                                                                                                         4.8 MB/s | 1.9 MB  00:00:00 Running transaction check

Running transaction test

Transaction test succeeded

Running transaction  

Installing : apr-1.7.2-1.amzn2.x86_64                                                                                       1/9  

Installing : apr-util-1.6.3-1.amzn2.0.1.x86_64                                                                                          2/9   Installing : apr-util-bdb-1.6.3-1.amzn2.0.1.x86_64                                                                                     3/9

  Installing : httpd-tools-2.4.55-1.amzn2.x86_64                                                                                          4/9   Installing : generic-logos-httpd-18.0.0-4.amzn2.noarch                                                                                  5/9   Installing : mailcap-2.1.41-2.amzn2.noarch                                                                                              6/9   Installing : httpd-filesystem-2.4.55-1.amzn2.noarch                                                                                     7/9   Installing : mod_http2-1.15.19-1.amzn2.0.1.x86_64                                                                                       8/9   Installing : httpd-2.4.55-1.amzn2.x86_64                                                                                                9/9   Verifying  : apr-util-bdb-1.6.3-1.amzn2.0.1.x86_64                                                                                      1/9   Verifying  : httpd-2.4.55-1.amzn2.x86_64                                                                                                2/9   Verifying  : apr-1.7.2-1.amzn2.x86_64                                                                                                   3/9   Verifying  : httpd-filesystem-2.4.55-1.amzn2.noarch                                                                                     4/9   Verifying  : mailcap-2.1.41-2.amzn2.noarch                                                                                              5/9   Verifying  : generic-logos-httpd-18.0.0-4.amzn2.noarch                                                                                 6/9   Verifying  : mod_http2-1.15.19-1.amzn2.0.1.x86_64                                                                                       7/9   Verifying  : httpd-tools-2.4.55-1.amzn2.x86_64                                                                                          8/9   Verifying  : apr-util-1.6.3-1.amzn2.0.1.x86_64                                                                                         9/9 Installed:   httpd.x86_64 0:2.4.55-1.amzn2                                                                                                               Dependency Installed:   apr.x86_64 0:1.7.2-1.amzn2                    apr-util.x86_64 0:1.6.3-1.amzn2.0.1        apr-util-bdb.x86_64 0:1.6.3-1.amzn2.0.1    generic-logos-httpd.noarch 0:18.0.0-4.amzn2   httpd-filesystem.noarch 0:2.4.55-1.amzn2   httpd-tools.x86_64 0:2.4.55-1.amzn2        mailcap.noarch 0:2.1.41-2.amzn2               mod_http2.x86_64 0:1.15.19-1.amzn2.0.1    Complete!

Stage 2: Start and enable Apache httpd server to start on boot

$ sudo systemctl start httpd

$ sudo systemctl enable httpd

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

$ sudo systemctl status httpd

  • httpd.service – The Apache HTTP Server

   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)

   Active: active (running) since Wed 2023-02-22 14:19:54 UTC; 25s ago

  Docs: man:httpd.service(8)

 Main PID: 2866 (httpd)

   Status: “Total requests: 1; Idle/Busy workers 100/0;Requests/sec: 0.0526; Bytes served/sec: 153 B/sec”

   CGroup: /system.slice/httpd.service

        ├─2866 /usr/sbin/httpd -DFOREGROUND

        ├─2867 /usr/sbin/httpd -DFOREGROUND

        ├─2869 /usr/sbin/httpd -DFOREGROUND

        ├─2883 /usr/sbin/httpd -DFOREGROUND

        ├─2896 /usr/sbin/httpd -DFOREGROUND

        ├─2903 /usr/sbin/httpd -DFOREGROUND

        └─2944 /usr/sbin/httpd -DFOREGROUND

The output above shows that the Apache httpd server is active and running on your EC2 instance.