TheLoudCloud
Published in

TheLoudCloud

Launch an EC2 instance with a php application

When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts.

The command below when passed as user data will run the commands to install a php application instead of you manually running the commands.

  • Launch an Ec2 instance with Amazon Linux 2 AMI.
#!/bin/bash
yum update -y
amazon-linux-extras install -y php7.2
yum install -y httpd
systemctl start httpd
systemctl enable httpd
usermod -a -G apache ec2-user
chown -R ec2-user:apache /var/www
chmod 2775 /var/www
find /var/www -type d -exec chmod 2775 {} \;
find /var/www -type f -exec chmod 0664 {} \;
cd /var/www/html
wget https://raw.githubusercontent.com/AbhishekGit-AWS/beanStalk/master/index.php
  • This script will setup and configure the php application. The php file being used here displays the EC2 instance details.

The above setting hosted the php application from github, you can also host your own code by transferring your local code to the EC2 instance.

--

--

Moving away from local everything to cloud everything. Discovering what’s safe, easy, cheap, conviniet.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store