Add following Custom data tab of EC2 Configuration | Advanced
Launching EC2 Webserver | httpd
!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
chmod 777 /var/www/html/
echo "<h1> hello from $(hostname -f)
</h1>">/var/www/html/index.html
Launching Php Webserver on EC2
#!/bin/bash
yum update -y
yum install httpd -y
yum install php -y
service httpd start
service httpd enable
chown -R ec2-user:apache /var/www
chmod 2775 /var/www
cd
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php