Table of Contents
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.
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.
Remember how difficult it was to launch a server the traditional way?
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.
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.)
Believe it or not, you can literally launch a new instance on EC2 with RightScale in a just a few minutes.
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.
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!
Sounds too good to be true? Let's preview the LAMP Server in a browser window.
Next, a browser window will open the index.html page that's been defined for the new LAMP Server.
Don't forget to terminate your instance! (Manage -> Servers)
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.
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.
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
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 .
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.
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:
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.'
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.
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.
The next step is customize the cloned ServerTemplate and define the appropriate Input parameters. Let's define some common input parameters for your ServerTemplate.
The following input parameters are required to launch a server with this ServerTemplate. Modify them accordingly.
|Input Name||Input Type||Description|
Provide the name of your PHP application. Example:
Enter the name of the S3 bucket that contains your application. For example:
Provide the name of your code package. For example:
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:
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:
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:
For the 'world' sample application provided by Rightscale above, use:
Provide the schema name of your database. For example:
For the provided 'world' sample application, use the value:
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.
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.
You are now ready to create the Server.
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:
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.)
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!
Once operational, you can view your PHP application in a browser window.
You should see a PHP information screen in your browser window, similar to what you saw earlier in this tutorial.
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.
© 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.