Intermediate Example

Objective

In this tutorial you will customize a RightScale server template to build your own LAMP server!  This tutorial will help you understand the basics of our pre-built templates and assets, as well as explain how to fully take advantage of them by cloning and customizing our server templates.  The key benefits are that the server templates 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.  Why recreate the wheel?

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, you will need to set up a Devloper account and use your own AWS credentials. See Sign up for AWS (AWS Credentials) and Add AWS credentials to RightScale.  

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 server template
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 server template

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

In this example we will customize the LAMP server template to launch a LAMP server on EC2. 

Go to Design -> Servers -> Server Templates.

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

18-medium_server_template.gif

 

Click the Clone button.  This will make a copy of the server template so that you can make changes to it.

02-medium_clone.gif

 

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

05-medium_renameAll.gif

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

Click on LAMP (clone) under the Private tab.

19-medium_private_server_templates.gif

 

Then click on the Scripts tab. 

31-medium_scripts.gif

Notice the list of boot, operational, and decomission scripts.  The default version of this server template 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 RightScripts.

Step 2: Create new RightScripts

Now we can customize the cloned server template to satisfy our needs by adding, removing, and rearranging RightScripts.

Let's modify the server template so that we can specify the URL of a specific web application and a MySQL dump file that we want to load. 

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

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

Create a RightScript for getting a MySQL DB from a URL

Go to Design -> Servers -> 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 server template and then remove/reorder some of the other RightScripts.

Go to Design -> Servers -> Server Templates.

Click LAMP (clone).  Click the Scripts tab.

First we want to replace some of the default scripts.
Remove the DB MySQL s3 mysqldump import v1 script by clicking the remove button. 

10-medium_remove_rightscript.gif

Now 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

 

Step 4: Rearrange the RightScripts

To change the order of the RightScripts, simply drag and drop a RightScript into the desired position.

22-medium_drag_and_drop_db.gif

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

 

Now remove the following RightScripts:

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

 

The final version should look like this:

33-medium_scripts_final.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 -> Servers -> 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.

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 -> Servers -> Server Templates.  Under the Private tab, click on the nickname of the "LAMP (clone)" server template.  Click on the Inputs tab and click Edit.

23-medium_edit_inputs.gif

Enter the following inputs:

 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_complete.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_1.gif

Troubleshooting

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.  Click on the email link and 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).  In about 5 minutes you will have a fully functioning LAMP server running on EC2!  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-75-101-208-94.compute-1.amazonaws.com).

32-medium_dashboard.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.  You didn't have to mess with any hardware, install any OS or software programs because the server templates automatically completed all of these tasks for you when you clicked the Launch button.  Server templates 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 -> Active Servers.  Click the shutdown button.

30-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 2 of 2 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
Viewing 2 of 2 comments: view all
You must login to post a comment.