Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Clouds > AWS > Tutorials > Beginner Examples > All-In-One LAMP Server

All-In-One LAMP Server

Table of Contents

Objective

This tutorial will introduce you to some of the key concepts behind the RightScale Cloud Management Platform and also show you how easy it is to set up, configure, and launch a fully functioning LAMP (Linux Apache MySQL and PHP/Perl/Python or other Programming language) server running on EC2 in 10 minutes using a RightScale ServerTemplate.  This tutorial is useful for any developer who wants to host a LAMP server on EC2. This tutorial is divided into two parts. Part 1 consists of launching a LAMP Trial ServerTemplate. Part 2 consists of cloning and modifying the LAMP All-In-One ServerTemplate. 

Note: This tutorial is designed to launch a Server in EC2.  If you want to launch a LAMP Server in the Rackspace Cloud, see the All-In-One LAMP Server tutorial for Rackspace.

Overview

lamp_allinone_diagram_v1.gif

ServerTemplates consist of a base image that contain a light-weight Linux installation (in our example shown below, CentOS ) with several RightScripts that help customize the image's configuration. In this tutorial you will use one of our LAMP all-in-one ServerTemplates to launch a fully functioning LAMP server on EC2.  By "all-in-one" we mean that the entire LAMP stack resides on a single server instance in the cloud, not multiple servers.  (See diagram.)

RightScale provides two types of LAMP all-in-one ServerTemplates.

  • LAMP All-In-One Trial - (All Users)  This ServerTemplate demonstrates how easy it is to launch a server on EC2 using the RightScale Dashboard.  This templates is great for demo purposes.  It's ideal for "free trial" users because it does not require a database or application to be uploaded to S3.  The database and application are included as attachments to RightScripts.
  • LAMP All-In-One with MySQL - (Free Edition/Pay Users)  This ServerTemplate is similar to the "trial" version except you can customize it for your own needs.  It's also configured to perform automatic backups to S3.
Overview of ServerTemplates

Remember how difficult it was to launch a server the traditional way?

  1. Perform a clean installation of your favorite OS
  2. Install and configure the required programs
  3. Launch, Fail, Debug, Repeat
     

Sound familiar? Now, with cloud computing, you can dynamically launch virtual servers with the click of a button!

RightScale created ServerTemplates to help automate this whole process.  It provides a very flexible way of configuring servers without ever touching a piece of hardware.  It also guarantees a consistent configuration across all servers, including new servers that are added to your deployment.

Each ServerTemplate can also be cloned and modified for all types of custom configurations.  

First, let's see how easy it is to launch a server using a ServerTemplate.  Then we'll show you how easy it is to customize a ServerTemplate for your own purposes.

Part 1: LAMP All-In-One Trial

Steps

Tip: We encourage beginner and intermediate level users to read the Help text. It functions like having a product Overview Guide. Some of our context-sensitive Help screens appear by default. If you wish to hide the help screens, simply click  the Hide Help button. (The Help/Hide Help action buttons toggle.)

Create a Server based on the "Trial" ServerTemplate

Believe it or not, you can literally launch a new instance on EC2 with RightScale in a just a few minutes. 

  • Go to Design > MultiCloud Marketplace > ServerTemplates
  • Search for the most recent version of the LAMP All-In-One Trial ServerTemplate (published by RightScale). In this tutorial, you will launch a LAMP server into the AWS US-East region.
  • Click the ServerTemplate name to drill down on additional details.
  • Click the Import action button to place a static copy of the ServerTemplate in your local view.
  • Click Add Server from the Default deployment.

    The following are basic descriptions for each field. For suggested values that you can use for this tutorial, please see the "Suggested Values" section below.

    Field Descriptions:

    • Deployment - A Server always exists within the context of a deployment.  Therefore, when you create a Server, you must specify into which Deployment the Server will be added.  Each RightScale account has a "Default" Deployment that's best used for testing purposes.  Select either the "Default" one or another Deployment that you've already defined.
    • ServerTemplate - Select the type of ServerTemplate from the pull-down menu.  When launching directly from a ServerTemplate, this has already been decided and will simply be listed in the dialog box.
      • Private - ServerTemplate from your private MultiCloud Marketplace.  That is, ServerTemplates that you either created from scratch, or imported and cloned.  These ServerTemplates are your own copy that you are free to customize.  They maintain their own lineage.
      • Imported - Anything you have imported directly from the MultiCloud Marketplace (which is a static copy).  Additionally, any ServerTemplates that you have subscribed to (which is a HEAD version, changing not a static revision.)
      • Then select the actual ServerTemplate name from another pull-down menu.  (e.g. Simple Linux Server)
    • Cloud -  What cloud the Server should be added to.  When adding a Server, this has already been selected via the Select Cloud action button, so in this dialog window you cannot alter it. It is simply displayed for informational purposes.
    • MultiCloud Image - Select the MCI to use or leave inherit from the ServerTemplate (default).
    • Instance Type - Select the Instance Type (e.g. small, medium, large, etc.) or inherit from the MultiCloud Image (default)
    • Nickname - Give a descriptive name for the Server's primary purpose.
    • SSH Key - Specify the (previously created) SSH Key to use.
    • Security Group - Select the (previously created) Security Group (or Groups) to use for security purposes.
    • Availability Zone - Select what Availability Zone (EC2) this Server should be in.  Recall that there are additional charges for traffic across zones.  Servers are typically placed in the same zone, unless the Deployment is working towards high availability across different zones. Some clouds have multiple zones or regions.
    • Elastic IP - Specify what EIP (or none) to use for the Server. 
    • Associate IP at launch - Normally you will leave this default (checked) so that an IP address is associated with the Server at launch. 

Suggested Values:

  • Provide a Nickname for your Server
  • Select the appropriate SSH key and Security Group (If you didn't create these values previously, you can select "New" next to the values and a window will display prompting you to enter the necessary information). 
  • Default values should suffice for the other fields:
    • MultiCloud Image and Instance Type (Inherit)
    • Pricing (On Demand)
    • EBS (leave unchecked)
    • VPC Subnet (none)
    • Elastic IP (none)
    • Associate IP at launch (leave checked)
    • Availability Zone (any)
    • Placement Group (none)
Launch the Server on EC2

You are now ready to launch the Server.  Click the Server's Launch action button.  Next, you will see a list of the predefined input parameters for the Server. Whenever you launch a Server, you'll have the option to change any of the Input parameters that are being inherited from the ServerTemplate itself (or from the Deployment level) before the Server is launched.  If one of the required Input parameters is missing, it will be highlighted in red.

Fortunately, the "trial" template has already been pre-configured with most of the required Inputs.  

Click the Launch button.   Follow the status of your Server as it boots up in the Events window.  If all goes well, you will see a transition from "pending" to "booting" to "operational".

Congratulations!  You just configured and launched a Server on Amazon's EC2 using one of RightScale's ServerTemplates.  Of course, you will have to wait a couple of minutes for the server to boot and become fully operational, but it's really that easy!  

screen-Click_Server-v1.png

Preview the LAMP Trial Server

Sounds too good to be true?  Let's preview the LAMP Server in a browser window. 

  • Click on the Nickname link (ex: My LAMP Server) to view more detailed information about the new Server. 
  • Click the Public DNS name link to preview your PHP application.

screen-LAMP-Trial-PublicDNS-v1.png

Next, a browser window will open the index.html page that's been defined for the new LAMP Server.

screen-LAMP-Trial-Success-v1.png

Don't forget to terminate your instance! (Manage -> Servers)

Part 2: LAMP All-In-One MySQL 5.0/5.1

Launch a Server using the most recently published version of the LAMP All-In-One with MySQL 5.0 - 11H1 or LAMP All-In-One with MySQL 5.1 - 11H1  ServerTemplate.

Steps

Prepare your Application

First, you must create a tarball of your PHP application code and a properly formatted gzipped dump of your MySQL database.

Note: The MySQL dump filename must follow the specified format:  'prefix-timestamp.gz'  Ex: myapp_prod_dump-20080416234.gz, where 'myapp_prod_dump' is the prefix.

 

If you do not have your own PHP application, or if you just want to launch a Server now and add your application later, you can download our sample files below and skip to the Upload your files to S3 step.

Note: After downloading the files, make sure that the filenames were not modified by your OS or browser settings.  Sometimes, extra characters will be added to the filename or the file extension may be changed or missing.  The files must have the correct filenames.

 

Alternatively, our services team has provided the source files for another test application (further known as the 'world' application). The database dump file comes directly from the 'world' database provided by MySQL as well. The link below for the application code will download a .tar.gz tarball file for you, so there is no need to create one in a separate step.

Create a MySQL database dump

The first step is to create a dump of your database.  It's important that the dump file is created correctly, so we suggest using the following commands to ensure that it is created in the proper format and has a proper name.  Simply fill in your username, password, and schema name and execute these commands. A dump will be created in your /tmp directory.  In the code below, you can replace 'myapp_prod_dump' with your own prefix if you so wish.

USER=
PASSWD=
SCHEMA=
suffix=`date "+%Y%m%d%H%M"`
mysqldump --single-transaction -u $USER -p$PASSWD $SCHEMA | gzip -c > /tmp/myapp_prod_dump-$suffix.gz
Create a tarball of your PHP application

Next you will need to create a tarball of your application.  To make things easy, change to the root directory of your application and execute the following command.

tar czf /tmp/myapp.tgz .
Upload your files to S3

Now that you have a dump of your database and a tarball of your application, you can upload those files to S3.  We suggest using two different S3 buckets, one for your application and one for your database backups, which will better isolate your application from all the database backups.  (This ServerTemplate is designed to take regular backups of your database and save them to S3.)  Remember to make a note of your bucket names, as you will need them later when setting Input values for APPLICATION_CODE_BUCKET and DB_MYSQLDUMP_BUCKET.

  • Go to Clouds > AWS Global > S3 Browser
  • Click the New Bucket action button. 

When naming the buckets, keep in mind that the namespace for S3 is global, so each bucket must have a completely unique name that nobody else is using.   Perhaps use the name of your site as a prefix.  Use the default location for each bucket.  The details surrounding bucket naming conventions is documented here, but the general best practices should suffice:

  • Names can contain lower case letters and numbers (and should be started with a letter or number)
  • Punctuation is ok too:  periods (.), dashes (-). Underscores (_) are legal, but not recommended (for reasons tied to DNS naming conventions)
  • Don't string punctuation together (e.g. "gregdoe-.bucket")
  • Names should be greater than 3 characters, and less than 63
  • Do not name a bucket with an IP address (for example, 1.2.3.4)

screen-S3Buckets-v1.png


Now click on the bucket for your application (e.g. dean-app1) and upload the tarball of your application.

If you created your own tarball, you can find the app in the /tmp directory (/tmp/myapp.tgz).  

Refresh your screen and you should now see the file in the application bucket.

 

Change the permissions of the file from 'private' to 'public-read.'

screen-ChangeToPublic-v1.png

Now repeat the process for you database dump file.  Be sure to add the .gz file to the database bucket.

If you created your own dump file, you can find it in the /tmp directory (/tmp/myapp_prod_dump-xxxxx.gz).   Be sure to change the permissions of the dump file as well from 'private' to 'public-read.'

Your application and database files are now in their respective S3 buckets where they can be easily retrieved when the server is launched.  Later, you will customize the ServerTemplate’s Inputs to specify these files. The files are accessed when you launch a server based on the ServerTemplate.

Select the LAMP "All-in-One" for MySQL 5.0/5.1 ServerTemplate
  • Navigate back to Design -> MultiCloud Marketplace -> ServerTemplates
  • Search for and locate the most recently published version of the LAMP All-in-One for MySQL 5.0/5.1 - 11H1.1 ServerTemplate.
  • ​Click on the ServerTemplate's name to drill down to further details of the ServerTemplate
  • Click the Import action button to place a copy in your account's 'local' view
Clone the ServerTemplate

Since it is much easier to clone and modify an existing ServerTemplate than creating one from scratch, the Dashboard allows you to clone ServerTemplates and RightScripts.  The ability to clone ServerTemplates and RightScripts is a very powerful tool for modifying and reusing components to save time and effort when deploying your application. 

  • Click the Clone action button towards the top of the ServerTemplate to create an editable copy under the account's 'local 'view. This will append a 'vX' suffix to the new ServerTemplate name, such as "LAMP v1" or similar.
  • Click on the nickname of the ServerTemplate to rename it something more descriptive if you wish (for example, you may want to append "(clone)" to the nickname).
Modify the ServerTemplate's Inputs

The next step is customize the cloned ServerTemplate and define the appropriate Input parameters.  Let's define some common input parameters for your ServerTemplate. 

  • Navigate to Design -> ServerTemplates
  • Click on the cloned ServerTemplate (e.g., "LAMP All-In-One with MySQL (clone)")
  • Click on the Inputs tab
  • Click on the Edit action button

The following input parameters are required to launch a server with this ServerTemplate.  Modify them accordingly. 

Input Name Input Type Description
 APPLICATION  Text

Provide the name of your PHP application. Example:

 

text: phpapp

 APPLICATION_CODE_BUCKET  Text

Enter the name of the S3 bucket that contains your application. For example:

 

text: rightscale-app1

 APPLICATION_CODE_PACKAGE  Text

Provide the name of your code package. For example:

 

text: myapp.tgz

 

If using the above 'world' sample application provided by Rightscale, use the full name of the tarball provided by the Github download link. For example:

 

rs-services-rs_phpmysql_testapp-123456.tar.gz

 DB_MYSQLDUMP_BUCKET  Text

Provide the name of your S3 bucket that contains your database.  It's also  where backups will be stored, which will be differentiated by the DB_BINLOG_PREFIX input in the filename. For example:

 

text: rightscale-db1

 DB_MYSQLDUMP_PREFIX  Text

Provide the prefix of the mysql dump file that you're going to use.  The prefix is all text leading up to the first hyphen in the dump filename. For example:

 

text: myapp_prod_dump

 

For the 'world' sample application provided by Rightscale above, use:

 

text: world

 DB_SCHEMA_NAME  Text

Provide the schema name of your database. For example:

 

text: photo_demo_production

 

For the provided 'world' sample application, use the value:

 

text: world

 WEBSITE_DNS  Text

Select environment variable (Env) as the input type and select the value EC2_PUBLIC_HOSTNAME of the current server. The EC2 Public Hostname is the fully qualified public hostname of the instance.

From the Dashboard, this is displayed as the "Public DNS name."  This is public as the name implies, and the hyperlink from the Info tab should render the index page of the application in your browser. 

For example:  ec2-75-101-247-165.compute-1.amazonaws.com

  • Click the Save action button when finished.
Commit the ServerTemplate

As a best practice, you should always create a static revision of a ServerTemplate by committing the ServerTemplate  whenever you make changes to a ServerTemplate's RightScripts or Inputs.  If you launch servers with the [HEAD] version of a ServerTemplate, its RightScripts and Inputs could change over time and possibly result in a stranded server the next time a new server is launched using the ServerTemplate.   

  • Click the Commit action button
  • Provide a helpful description of your changes in the "Message" field
  • Click the Commit action button when you are through.  A new revision (e.g., "Rev 1") is saved.
Create the Server

You are now ready to create the Server. 

  • Select the [rev1] version of the ServerTemplate in the "Revision" timeline bar near the top of the ServerTemplate display
  • Click the Add Server action button.
    • Select the correct Cloud (AWS US-East in our example) and the desired Rightscale deployment, then click the Continue action button.
    • After selecting the Continue action button to add a server to your deployment. You will encounter an Add Server Assistant.

Note:  For suggested values that you can use for this tutorial, please see the "suggested values" section below.

 

Suggested Values for Server Details Tab:

  • Select your desired SSH Key and Security Group from their drop down menus
  • Select an Availability Zone (e.g., us-east-1a) if desired
  • "MCI" and "Instance Type" fields -  Set to "inherit"
  • "Elastic IP" field - Set to "none"
  • "Associate IP at launch" field - Leave selected
  • Click the Confirm button followed by the Finish button on the next page to finish adding the server to the deployment.
Launch the Server

You are now ready to launch the server.  Click the server's Launch action button.

Next you may see a list of the Input parameters that you just defined in the ServerTemplate. 

Remember, whenever you launch a server, you'll have the option to change any of the Input parameters that are being inherited from the ServerTemplate itself (or from the deployment level) before the server is launched.  If one of the required Input parameters is missing, it will be highlighted in red.  (There should be none in red for this tutorial.)

  • Click the Launch action button to launch your new server in EC2

 

Congratulations!  You just customized a ServerTemplate and launched a new LAMP server on Amazon's EC2 cloud.  In a couple of minutes you will have a fully operational server on EC2 running a PHP application! 

Preview your PHP Application

Once operational, you can view your PHP application in a browser window.

  • Click on the server's nickname link, accessible from the Manage > Servers menu
  • Click the server's "Public DNS name" link under the server's Info tab

You should see a PHP information screen in your browser window, similar to what you saw earlier in this tutorial.

Terminate the ServerEdit section

Don't forget to terminate your server when you are done to avoid unwanted usage fees.  You can view a list of servers from the Manage > Servers > Active tab and terminate them from there using the column on the right hand side. Additionally, termination can be issued using the Terminate button from the top of the server's Info tab.

See also

Basic Example

You must to post a comment.
Last modified
16:18, 15 Jul 2013

Tags

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.