Intermediate Example

Objective

In this tutorial you will customize a RightScale ServerTemplate to build your own LAMP (Linux Apache MySQL and PHP/Perl/Python or other Programming language) server!  This tutorial will help you understand the basics of our pre-built templates and assets.  It will also explain how to take full advantage of these benefits advantage by cloning and customizing RightScale ServerTemplates.  The key benefits are that the ServerTemplate  get you up and running quickly, while also giving you the flexibility to clone and customize these templates so that you can reuse and leverage all the pre-existing assets.  There is no reason to recreate the wheel so to speak.

The Intermediate Example can be completed with any type of account (Free Trial, Developer, Premium). 

If you do not have a RightScale account, sign up for a Free Trial account at http://www.rightscale.com. If you are running a trial account and your EC2 time has expired, and you are not ready to sign-up for one of our pay editions, you can create an AWS account and set up a Free Developer account.   See Upgrade Your Account to learn how to sign-up for AWS and add your credentials into the Dashboard.

If you are using a free trial account, you must activate your trial account by clicking on the link that was emailed to you from notifier@my.rightscale.com.

This tutorial is divided into 7 Steps:

Step 1: Clone and rename the LAMP ServerTemplate
Step 2: Create new RightScripts
Step 3: Remove and add new RightScripts
Step 4: Rearrange the RightScripts
Step 5: Add credentials
Step 6: Configure the input parameters
Step 7: Launch the web server on EC2

 

Step 1: Clone and rename the LAMP ServerTemplate

RightScale offers several ServerTemplates that are publicly available to all users.  Since you cannot make changes to these public ServerTemplates directly, you'll first have to clone it and then customize it accordingly.  But, these public ServerTemplates are an excellent way to get a head start instead of trying to build your own ServerTemplate from scratch.

In this example we will customize the LAMP ServerTemplate to launch a basic LAMP server on Amazon's EC2. 

Go to Design -> ServerTemplates.

Click on the RightScale tab.  You will see list of public/premium ServerTemplates that are maintained by RightScale that you can clone and customize for your own deployment.  For this example, click on the most recent LAMP ServerTemplate.

NOTE:  For multi-cloud support, you may notice buttons that are labeled slightly different, including the cloud name.  For example, "New EC2," "New Flexiscale," etc.

01-medium_server_template2.gif

 

Click the Clone button.  This will save a copy of the ServerTemplate to your Private tab so that you can make changes to it.

02-medium_clone2.gif

 

Now rename the cloned LAMP ServerTemplate.  Simply click on the name and type a new name, "LAMP (clone)" and click OK.

05-medium_renameAll.gif

Go to Design -> ServerTemplates.  Under the Private tab you should now see the cloned LAMP ServerTemplate.    Cloned templates are automatically generated with incrementing version numbers.  Therefore,  even if you clone a v4 ServerTemplate, it will appear as v1 when you clone it.  Once you have successfully cloned the ServerTemplate, you're ready to start customizing it.  But first, let's see what's already inside the LAMP ServerTemplate. 

Click on LAMP (clone) under the Private tab.

19-medium_private_server_templates2.gif

 

Then click on the Scripts tab. 

31-medium_scripts3.gif

Notice the list of boot, operational, and decomission scripts.  The default version of this ServerTemplate is designed to load an application and a MySQL dump that are already stored on Amazon S3.  But, to reduce this dependency on S3, we are going to remove these scripts and replace them with new RightScripts that get a database and application that we've already uploaded for you.

NOTE: For a list of all the RightScripts and their descriptions see List of RightScripts.

 

Step 2: Create new RightScripts

Now you can customize the cloned ServerTemplate to satisfy our needs by adding, removing, and rearranging RightScripts.

Modify the ServerTemplate so that you can specify the URL of a specific web application and a MySQL dump file that you want to load. 

You'll need to create two new RightScripts that do the following:

  • Gets a MySQL database from a URL and applies it to the ServerTemplate
  • Gets a PHP web application from a URL and applies it to the ServerTemplate

Create a RightScript for getting a MySQL DB from a URL

Go to Design -> RightScripts.

Click the New button to create a new RightScript.  Name it get and apply phptest db and paste the following code into it.  This RightScript will download and apply the MySQL dump that is pointed to by the variable DUMP_GZIP_URL.   We've already uploaded a db and app to S3 that you can use for this tutorial.  Links for these files will be provided later in this tutorial when we configure the inputs. 

#!/bin/bash -e
cd /tmp
wget $DUMP_GZIP_URL -O dump
gunzip -c dump | mysql

 

08-medium_new_rightscript.gif
Click Save

Create a RightScript for getting a PHP App from a URL

Click on RightScripts and click New to create another RightScript.

Name the new RightScript, get and apply phptest app and paste the following code into it:

#!/bin/bash -e 

## Check if optional application root is specified
if [ -z "$OPT_WWW_DOCUMENT_ROOT" ]; then
  content_dir="/home/webapps/$APPLICATION/current"
else
  content_dir=$OPT_WWW_DOCUMENT_ROOT
fi

mkdir -p $content_dir
cd /tmp

#get application tarball from S3
wget $APP_TAR_URL -O app

#install applicaton
tar -xzf app -C $content_dir

The script above does the following:

  • Sets the variable content_dir to be OPT_WWW_DOCUMENT_ROOT if it is specified, or to /home/webapps/$APPLICATION/current if it is not specified.
  • Downloads the tarball pointed to by APP_TAR_URL to this directory.

20-medium_new_rightscript.gif

Click Save.

 

 

Step 3: Remove and add new RightScripts

Now we need to add the new RightScripts to the cloned ServerTemplate and then remove/reorder some of the other RightScripts.

Go to Design -> ServerTemplates.

Click LAMP (clone).  Click the Scripts tab.

First we want to add the new RightScripts that we just created: get and apply phptest db and get and apply phptest app

Select them from the private RightScript pulldown menu and add them as boot scripts. 

09-medium_add_rightscript1.gif

After selecting the "Add" button, the RightScale Dashboard header displays "RightScript was successfully added" and the Boot Scripts displays them as "[HEAD]" versions.

 

Step 4: Rearrange the RightScripts

To rearrange the order of RightScripts, use the up/down arrow icon next the the RightScript and simply drag and drop it into place. 

  • Place get and apply phptest db after DB MySQL server install
  • Place get and apply phptest app after WEB PHP install

 

Remove the following RightScripts:

34-medium_remove_script.gif

  • DB MySQL s3 mysqldump import (boot script)
  • WEB app s3 code checkout (boot script)
  • DB MySql s3 continuous mysqldump backups (boot script)
  • DB MySQL s3 mysqldump backup (operational script)

 

The final version should look like this:

33-medium_scripts_final3.gif

 

 

Step 5: Add credentials

To access the database, we will need to grant access to a user. Instead of entering a username/password in plain text, RightScale has developed a credential store to safely hold your passwords.  Let's create two credentials for the DB username and password.  The Value field is where you enter your username or password.

Go to Design -> Credentials.   Click New Credential.

12-medium_new_credentials.gif

Name the first credential, DBAPPLICATION_PASSWORD (not case-sensitive) and enter app_password for the value (you can leave the description blank) and click Save.  The RightScale Dashboard header displays "Credential was successfully created."

Create a second record named, DBAPPLICATION_USER and enter app_user for the value and click Save.

You now have two credentials that will be used in order to access the database.

13-medium_list_credentials.gif

 

 

Step 6: Configure the input parameters

Now we are ready to configure the input parameters.

Go to Design -> ServerTemplates.  Under the Private tab, click on the nickname of the "LAMP (clone)" ServerTemplate.  Click on the Inputs tab and click Edit.

23-medium_edit_inputs2.gif

Edit the following inputs accordingly:

 APPLICATION  Text     phptest
 APP_TAR_URL  Text http://s3.amazonaws.com/rightscale_tutorials/phptestapp.tgz
 DBAPPLICATION_PASSWORD    Cred DBAPPLICATION_PASSWORD
 DBAPPLICATION_USER  Cred DBAPPLICATION_USER
 DB_SCHEMA_NAME  Text phptestdb
 DUMP_GZIP_URL  Text http://s3.amazonaws.com/rightscale_tutorials/phptest.sql.gz
 WEBSITE_DNS  Env EC2_PUBLIC_HOSTNAME

   

 

 

 

 

 

 

 

 

The list of inputs should now look like the following screenshot. 

24-medium_inputs_complete3.gif

If everything looks great, click Save.

 

Step 7: Launch the web server on EC2

After you have entered all of the necessary input parameters, you are now ready to launch the server.

Click the Launch button.

25-medium_launch_2.gif

 

Troubleshooting

47-insufficient_message.gif
If you receive an error message saying that your account has insufficient funding to perform this action, you need to verify your email address.  Go to your email account and check for an email confirmation from notifier@my.rightscale.com.  It may be in your bulk/spam folder.  When you click the email validation link your account should be activated.  Refresh and launch the server again.  If you are still experience problems, please contact  support@rightscale.com.

Verify your settings and click Launch.

26-medium_launch_2.gif

To track its progress, go to the Dashboard home page (click on the RightScale logo).  Depending on how often you check its status, you should see a progression from "pending" to "booting" and eventually "operational."  In about 5 minutes you will have a fully functioning LAMP server running on EC2! 

 

Troubleshooting using Audit Entries

To check progress in a more detailed fashion, navigate to Manage > Servers and select your "Lamp (clone)" server under the Active tab.  Select the Audit Entries tab.   Depending on your current progress, you will see something like this:

36-medium_audit.gif

In our example, you can see the server instance status progression under the "Summary" column of the table.  Select a link under Summary to view helpful troubleshooting information.  For example, if your server did not progress from pending to booting to operational, the last link could be "stranded" (not operational).  Look at the "stranded" audit entry to view in-depth information that can help you troubleshoot the problem.  You will see the boot scripts starting, logging information, etc.  Warning and errors can also be displayed in the audit entries, which provides a starting point for resolving the issue.

 

Once your server is fully operational, you can preview your new LAMP server in a browser window.  Click on the (Public) DNS name (ex: ec2-72-44-38-255.compute-1.amazonaws.com).

32-medium_dashboard2.gif

You should now see the default PHP page.  You should also receive an email from notifier@my.rightscale.com informing you that the 'LAMP' instance is now operational.

29-medium_browser.gif

Congratulations!  You just learned how easy it is to launch a LAMP server on EC2 with the RightScale Dashboard.  The best part about launching servers on the cloud is that you no longer have to mess with any hardware, install any OS or software programs, because the ServerTemplates will automatically complete all of these tasks for you when you click the Launch button.  ServerTemplates make it easy to launch instances on EC2 while also giving you the control and flexibility to customize each server accordingly.

Don't forget to terminate your instance.  Go to Manage -> Servers and click the shutdown button.

35-medium_shutdown.gif

 

 ----------------------

Did you find this document helpful?  Please feel free to leave us a comment below.  We're always looking for ways  to improve our documentation.  Thanks!

 

Tag page
Viewing 4 of 4 comments: view all
When I attempt to clone the Lamp V2 server template, I actually end up with a clone of the Lamp V1 template. Is anyone else having this problem, or am I missing something obvious?

I think that we also need the URL to the database dump for the $DUMP_GZIP_URL in order to run the 'get and apply phptest db' RightScript. edited 01:46, 29 Apr 2008
Posted 00:48, 29 Apr 2008
Nope, that is the proper behavior. When you clone a template it starts at v1 then increments from there, so actually what you are getting is a clone of the v2 template that is named v1. If you were to clone it again, it would be named v2.

As for the URL, whoops, my mistake. I added a link :)
Posted 22:45, 6 May 2008
Can you explain the last paragraph in Step 1? Both the original scripts and the scripts used in this tutorial get files from S3. I'm confused by the statement, "...to reduce the dependency on S3..."

I see that the methods for obtaining the files from S3 are different ('sc3cmd get' and 'wget'). Is there a reason to use one over the other?

Thanks!
Mary
Posted 21:37, 21 Dec 2008
Hi Mary,

Yes, that is worded a little confusing. Let me see if I can clarify...

The scripts are originally designed to fetch objects in a private bucket in you S3 account. This requires populating your bucket with the necessary objects, and authenticating with S3 for the transfer. We chose to take this part out to reduce the complexity and also to permit trial users to use this tutorial.

Since the objects are hosted in a public S3 bucket, they are addressable with http and using wget for this is very simple. You certainly could use s3cmd instead, but it is more complex.

hope this helps,

Martin
Posted 18:04, 23 Dec 2008
Viewing 4 of 4 comments: view all
You must login to post a comment.