RightScale offers a collection of free ServerTemplates to developers. This tutorial will show you how 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.
NOTE: You do not have to be a Premium RightScale user to complete this tutorial.
In this step you will create a tarball of your PHP application code and a gziped dump of your MySQL database.
NOTE: The MySQL dump filename must follow the specified format: 'prefix-timestamp.gz' Ex: myapp_prod_dump-20080416234.gz
If you do not have an application already built, or if you just want to launch a server now and add your app later, you can download our sample files and skip to step 2.
- Sample PHP application: myapp.tgz
- MySQL database dump file: myapp_prod_dump-200804161345.gz
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.
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. You will need to create two buckets (folders) on S3, one for your application and one for your database backups.
Login to the RightScale Dashboard and go to Clouds -> AWS-> S3 Browser.
Click the New Bucket 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.

Now click on the bucket for your application and upload the tarball of your application.
If you followed Step 1, you can find the app at /tmp/phptestapp.tgz. If you are using our temporary files, you will browse to and upload those files from wherever you placed them on your local hard drive into your uniquely named S3 Bucket.

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

Now repeat the process for you database dump file. Be sure to add the .gz file to the database bucket.
If you followed Step 1, you can find the app in the /tmp folder with a prefix of myapp_prod_dump-. It should look like this once you upload and refresh.

Now that the database and application files are in buckets on S3, we're ready to configure RightScale's LAMP server template.
Go to to Design -> ServerTemplates and click on the RightScale tab.
In this tutorial we will use a public all-in-one LAMP ServerTemplate that has everything already preconfigured for a basic installation. By default, it will also automatically take nightly backups of the database to S3. Find the latest version of the LAMP ServerTemplate and click the green launch button.


Be sure to select the production SSH key. You can use the default settings for everything else. Click Launch.
The next window will highlight the required input parameters in red that need to be defined before we can properly launch the server.
Next, we'll enter valid input parameters for each required field.
If you followed Step 1, you can set the following values.
| APPLICATION | Type: phpapp |
| APPLICATION_CODE_BUCKET | Enter the name of the S3 bucket that contains your application. |
| APPLICATION_CODE_PACKAGE | Type: myapp.tgz |
| DBAPPLICATION_PASSWORD | Type: your password or select the credential |
| DB_MYSQLDUMP_BUCKET | Enter the name of the S3 bucket that contains your database. |
| DB_MYSQLDUMP_PREFIX | Type: myapp_prod_dump |
| DB_SCHEMA_NAME | Enter the schema name of your db. If you followed Step 1, enter phptestdb. |
| WEBSITE_DNS | Select environment variable (Env) as the input type and choose EC2_PUBLIC_HOSTNAME. |

Now you're ready to launch the LAMP server. Click the Launch button. The RightScale Dashboard header displays "Launched server LAMP v3." You will also see the LAMP server pending under the Recent Events list. But, in a few minutes you will have a fully functional LAMP server!
Once the LAMP server is operational, click the LAMP v3 nickname.

To view the application, click on the public DNS link.

You should now see your PHP application in a browser window. If you used the application file that was provided, you should see the following screen.

You can also conveniently ssh into your instance by clicking the SSH Console button. ![]()
Congratulations! In a few steps, you just launched a LAMP server on EC2 by using one of RightScale's public ServerTemplates.
And don't forget to terminate your instance! Unless of course, you don't mind paying Amazon $0.10/hr.

----------------------
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!
We now have charges for cross Zone bandwidth!!
Use a single zone for all of the servers is a Deployment or you will be charged. For a LAMP server this is not a problem, but for a separate Server and database Deployment you need to define the Zone.
I would recommend that you pick a Zone for each Deployment as Best Practice to keep you from later issues then you scale up.
The exception to this is for Two Zone deployments for improved fault survival. Then you need to pick the Zone for each server with care.
Best Practice for now, never use ANY Zone. Pick one or more as needed and set the value. Never leave this value to chance.
Ed@Rightscale.com