Install LAMP Stack Using Cloud Formation

01 / Jul / 2014 by Vikash Jha 1 comments
AWS Cloud formation  is a service used to create and manage a collection of other AWS services. This service is used to automate the infrastructure setup and deployment.

In this article, we will be launching a LAMP Stack Instance using Cloud Formation. For this we are using Ubuntu Server 14.04 LTS (PV) – ami-9a7724c8 (64-bit)

Steps to Launch:

1) Create a .json file
2) Open AWS Console
3) Browse to Cloudformation, CREATE STACK and upload the .json file

Create a .json file

 "Resources" :

      "Type": "AWS::EC2::Instance",
         "ImageId" : "ami-9a7724c8",
         "KeyName" : "demo",
         "SecurityGroups" : [ "demo" ],
         "UserData" : {"Fn::Base64" : {"Fn::Join" : ["", [
           "# Launching Instance",
           "apt-get -y install apache2 \n",
           "apt-get -y install mysql \n",
           "apt-get -y install mysql-server \n",
           "apt-get -y install php php5-mysql \n"
            ] ] } }
    "WebsiteURL" : {
      "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [        "WebServer", "PublicDnsName" ]}]] },
        "Description" : "URL for newly created LAMP stack"
 **Note: Keyname and Security groups must exists on your account 

Open AWS Console > Browse to Cloud Formation >Create Stack


Once you click Create Stack button, it will ask for the Stack Name and the .json file.


Upload the .json file and Follow the wizard. The next wizard ask you to enter the Key Value name for the Instance:


Click the Next Button and the launch the stack. Once you launch the stack, you will get the following screen with launching process events.


If everything goes well, you will get the the CREATE_COMPLETE message in the Status Tab. If any error occurs then a ROLLBACK event is invoked which will delete the stack.

Since we got the CREATE_COMPLETE message with a output parameter that we have defined in our json which returns the public DNS name of the Instance.


By Clicking on the output URL, it takes us to the apache default page:


We can check the Console to see our running Instances:


We can see the Public DNS is same.

To Terminate this Instance we can delete the stack from the Cloud Formation Wizard. Deleting the stack will terminate all the instances launched by that stack.




comments (1 “Install LAMP Stack Using Cloud Formation”)

  1. Patrick R

    I appreciate your detailed information here but want to add some easy and helpful way to install LAMP CF on Amazon EC2. For that, you can use ready to run cloud image (AMI) available on AWS marketplace.
    For that, go to AWS marketplace and search for LAMP cloudformation. You will get a list of this CF providers. Choose any one of them and follow the provided usage Instructions.
    Here you can find the simple steps to setup LAMP CF on AWS


Leave a comment -