All-in-one LAMP Server

Objective

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.

This tutorial is divided into 4 steps:

Step 1: Prepare your application
Step 2: Upload your files to S3
Step 3: Configure the LAMP ServerTemplate
Step 4: Launch the LAMP server

 

 

Step 1 - Prepare your application

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.


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.

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 .

 

 

Step 2 - 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.  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. 

01-lamp_new_s3_bucket2.gif

 

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.

02-lamp_bucket_list.gif


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.

03-lamp_upload_app.gif

 

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

04-lamp_file_in_bucket.gif

 

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.

05-lamp_db_in_bucket.gif

 

 

Step 3 - Configure the LAMP ServerTemplate

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.

06-lamp_launch_lamp_template3.gif

 

07-lamp_add_server_form3.gif

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.

 

09-lamp_complete_fields2.gif

 

 

 

Step 4: Launch the LAMP server

10-lamp_recent_tasks.gifNow 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.

12-lamp_operational2.gif

 

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

13-lamp_public_dns2.gif

 

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.

14-lamp_view_app.gif

 

You can also conveniently ssh into your instance by clicking the SSH Console button. 11-lamp_ssh_icon.gif

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.

 

16-lamp_terminate2.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

Files 2

FileSizeDateAttached by 
 myapp.tgz
No description
453 bytes00:59, 17 Apr 2008martinActions
 myapp_prod_dump-200804161345.gz
sample_dump
691 bytes17:50, 16 Apr 2008martinActions
Viewing 1 of 1 comments: view all
NEW Information!

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
Posted 06:41, 29 Jul 2008
Viewing 1 of 1 comments: view all
You must login to post a comment.