Deploy Application in Amazon Beanstalk inside free EC2 Instance with RDS

Amazon has virtual cloud server (instance) and many other web services. They offers a 1 year free micro tier to be used by anyone who own an international currency Debit/Credit card like Payoneer debit master card. There are several services included with the free tier that can be used along with the EC2 instance without any extra charge. Beanstalk deployment framework is one of the free services you are eligible for.

For no additional charge, AWS Elastic Beanstalk allows you quickly and easily deploy your Java, PHP, Python, Ruby, and .NET applications using many of the services offered in the free usage tier.” -Amazon. Beanstalk is similar to other deployment frameworks like appfog, pagodabox etc. Moreover if you use Beanstalk then you will still have access to your virtual cloud server in which the deployment will be running. “Behind the scenes, Elastic Beanstalk handles the provisioning of a load balancer and Amazon EC2 resources.” -Amazon. Thats why I prefere Beanstalk than others who are in my knowledge.

In this post we will cover the steps of creating an account for Amazon EC2 free tier, configuring local machine for Amazon CLI tools, creating a sample app locally, creating an elastic beanstalk php environment, deploying a sample php app, creating an Amazon RDS and connecting to it via PHP and mySQL workbench, git version controlling of the deployed app, setting up a custom classified domain to our newly deployed app environment. Tired to read these ? I am sure you will feel best after having this journey 🙂

1. Create an account for Amazon web service from here . You can see the service list that will be included with your free tier for your further using. Note that, the sign up process is simple and you will be asked to provide your card detail on the second step and finally you will have to verify your phone number. You will have to put your phone number then to click “call now” button then a 4 digit pin number will be appeared on your browser. After that an automated call will reach your phone. You should either speak the pin number slowly or input the pin number in your mobile keypad if it supports touchtone functionality. I always spoke the pin after listening the bot girl’s voice 🙂

2. Now prepare your local machine for working with Amazon CLI tools. I assume you have already Git, Ruby, Python installed in your local machine if you are at least a mid level developer and use version controlling frequently :). If I am wrong then:

a. Git. To download Git, go to Make sure you have at least version 1.6.6 or later. To verify if Git is already installed, type the following command at the command prompt:

b. Ruby version 1.8.7 or later. To view and download Ruby clients, go to To verify if Ruby is already installed, type the following command at the command prompt:

If Ruby responds, and if it shows a version number at or above 1.8.7, then you have the correct version installed.

c. Download AWS DevTools, which is part of the command line interface package, at the AWS Sample Code & Libraries website. Extract the .zip any where.

d. To add “eb” files to your path enter the following command in your Terminal:

Here “/Users/nuhilmehdy/….” is my own path. Change it in your way.

3. Create a app directory in your local machine and name it for example mybean. Open the Mac Terminal and go into that directory:

First we created a directory mybean then entered into it and then initialized it as a git repository. Now, from your Git repository directory, run You can find in your downloaded AWS DevTools/Linux/ directory.

Note, You need to run this script for each Git repository for further more new apps.

Add a php script along with some code inside the mybean:

Paste the following code and ctrl+x to save the file:

Now commit the changes with following git commands:

4. Creating a deployment environment in beanstalk is very easy if you use graphical interface. If you signed up successfully for Amazon web service then by clicking this link you can go to your Amazon console home. Here you can see so many services to be consumed by you. We will use the Elastic Beanstalk service.

Screen Shot 2012-12-23 at 2.08.25 PM

Click on Elastic Beanstalk. You will see a screen like following.

Screen Shot 2012-12-23 at 2.14.46 PM

Hmm, select php and click start as we going to deploy a PHP app. Then you should see the following screen where a deployment environment along with an application has already been created:

Screen Shot 2012-12-23 at 3.26.24 PM

At this stage a sample application with some documentation files have been deployed automatically by Beanstalk. If you click on the URL: under Default-Environment ‘s Overview tab then you should see the deployed application’s page on the browser. But this is not our application, right? We developed one in locally and will now deployed it on our newly created environment.

5. Deploying the local app to the environment is all about some aws git commands. Again open the terminal and I assume you are inside the mybean directory. Enter the following command:

It will ask some question to you now. Look out here for the first (AWS Access Key) and second (AWS Secret Key) question answers. For (AWS Region) simply press enter. Then, for (AWS Elastic Beanstalk Application) type “My First Elastic Beanstalk Application” without quotes and for (AWS Elastic Beanstalk Environment) type “Default-Environment” without quotes as you can see these in the above screen shot.
Finally enter the following command:

Done! Now in your Elastic Beanstalk console you will see all the versions of this app and currently deployed git version under Versions Tab and Environment area correspondingly, like the following screen:

Screen Shot 2012-12-23 at 6.04.41 PM

If you click the URL: then you should see what we were working for 🙂

Screen Shot 2012-12-23 at 6.08.00 PM

N.B. Don’t be upset. The “Creating RDS and connecting to it via PHP and mySQL workbench” and “setting up a custom classified domain to our newly deployed app environment” parts will be here tomorrow. Stay tunned …

3 thoughts on “Deploy Application in Amazon Beanstalk inside free EC2 Instance with RDS”

Comments are closed.