This is a short post summarizing some issues I encountered while installing apache on an EC2 – running amazon linux 2. (Also read Configuring Apache and Certbot. Also read – Installing certbot on your amazon linux 2 EC2 instance )

Check your ec2 linux flavor

cat /etc/os-release. lsb_release

Install Apache on ec2

 sudo yum -y install httpd
 sudo service httpd start

Change from ssm-user to ec2-user  (If you logged in via the systems session manager)

sudo su ec2-user
Create a testweb directory and a sample hello.html

sudo mkdir testweb  sudo chown  ec2-user testweb sudo chmod -R o+r testweb
cd testdir    

Create a sample hello.html file.

$ echo "<html><h1>Hello from EC2 Apache</h1></html>" > hello.html    

Test through a browser

http://EC2-public-DNS/testweb/hello.html

What could go wrong ?

1. Ensure your SG is set up correctly – to allow inbound 80 traffic

apache on ec2 Security Group
apache on ec2 Security Group

2. Ensure you have a virtual host defined in your httpd.conf file (see examples here )

sudo vi /etc/httpd/conf/httpd.conf

# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
    DocumentRoot "/www/example1"
    ServerName www.example.com

    # Other directives here
</VirtualHost>
<VirtualHost *:443>
    ServerName www.example2.com
    DocumentRoot /var/www/example2.com/public_html
    ServerAlias example2.com
    ErrorLog /var/www/example2.com/error.log
    CustomLog /var/www/example2.com/requests.log combined
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/example2/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/example2/apache.key
</VirtualHost>

Check the error log and the access log for apache for errors

egrep -v '#|^$' /var/log/httpd/access.log  OR cat  /var/log/httpd/access.log | grep error cat  /var/log/httpd/error_log | grep error 

Summary

While not difficult, I encountered a few hiccups installing and configuring apache on ec2 (setting up a virtual host, ensuring that I switched to the ec2-user…).  Setting up apache on amazon linux should be straightforward. There is a nuance that this post did not deal with – that of storing your web folders on the EBS volume.




Need an experienced AWS/GCP/Azure Professional to help out with Data Protection on the Public Cloud? Set up a time with Anuj Varma.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.