webserver on amazon linux Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/tag/webserver-on-amazon-linux/ Production Grade Technical Solutions | Data Encryption and Public Cloud Expert Tue, 27 Apr 2021 01:19:27 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://www.anujvarma.com/wp-content/uploads/anujtech.png webserver on amazon linux Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/tag/webserver-on-amazon-linux/ 32 32 Apache on EC2 https://www.anujvarma.com/apache-web-server-on-amazon-linux-2/ https://www.anujvarma.com/apache-web-server-on-amazon-linux-2/#comments Tue, 30 Jun 2020 12:03:11 +0000 https://www.anujvarma.com/?p=7305 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 – […]

The post Apache on EC2 appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
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.

The post Apache on EC2 appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/apache-web-server-on-amazon-linux-2/feed/ 1