Install, configure and host a website on an EC2 instance using Apache

Install, configure and host a website on an EC2 instance using Apache

In this tutorial, I will provide step-by-step guidance on how to install the Apache web server on an EC2 instance, enable the web service, and display the default web page. Furthermore, I will show you how to copy a web template from your local PC to the remote server and unzip the folder contents into the html folder, allowing the index page to display when the instance IP address or DNS name is typed into a webpage. Let's dive in.

This tutorial assumes that you have installed your EC2 instance if you haven’t seen my tutorial on how to install an EC2 instance on AWS

Connect to your EC2 instance

1.       Connect to your instance and ensure your software packages are up to date using

·       sudo dnf update -y

2.       Install the latest versions of the Apache web server and PHP packages on the EC2 instance

  •   sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel

3.       Start the Apache web server

·       sudo systemctl start httpd

4.       Use the systemctl command to configure the Apache web server to start at each system boot

·       sudo systemctl enable httpd

you can verify that httpd is working by running this command

·   sudo systemctl is-enabled httpd

5.       Try to open the webpage using the instance public IPv4 address or the public IPv4 DNS, this should return with connection timing-out error. This is because port 80 isn’t open in our security group

Open Port 80 in the Security Group

1.       In the EC2 instance navigation pane, open Security Groups in the Network & Security section

2.       Select the security group to be edited. In the Actions drop-down filter, choose Edit inbound rules

Article content

3.       On the Edit inbound rules page, click the Add rule button, under Type, select HTTP, under Source, select Anywhere IPv4. Click Save rules

Article content

4.       Refresh the web page. Your default web page should be displayed.

 

Change the default webpage to a custom webpage

As the default webpage isn’t fancy enough, I will change it to a more customized static webpage. This process will involve copying the custom webpage files from my local PC to the AWS EC2 instance.

1.       First, I create a directory in my EC2 instance to copy the web folder into

·       Mkdir Webfolder

2.       Next, from your PC CLI, navigate to the location where you have the custom website downloaded and run these commands to transfer the folder to your EC2 instance

·       scp -i ec2instancekeypair foldername ec2username@publicdnsname:directorylocation

Article content

3.       Verify that the folder was copied into the right directory on your EC2 instance

4.       Unzip the folder on your EC2 instance into the html folder using this command

·       Unzip foldername -d /var/www/html

Article content

5.       Change the directory into the unzipped folder in the html folder, and copy the entire content into the html folder. Ensure the index.html file is in the html folder

·       cp  -r * /var/www/html

6.       Restart the Apache web service using

·       systemctl restart httpd

7.       Refresh the webpage, you should have the new webpage displayed in the browser.

To view or add a comment, sign in

More articles by Oladepo, Kunle

Insights from the community

Others also viewed

Explore topics