Web Programming

CSC 210, Spring 2012

(Monday and Wednesdays, 2:00-3:15pm in CSB 209)

Amazon Web Services Tutorial

This tutorial teaches you how to set up a server on Amazon Web Services. You will be doing all of your assignments on your server.

Contact Tutorial

Your contact for this tutorial is Anna Loparev. Please direct questions about this assignment to Anna (see the Contact Page) because she will best know what's going on. You can also always contact Jeff, who may end up forwarding your question to Anna.

Creating an Account

  1. Go to the Amazon Web Services Homepage.
  2. Click on Sign Up or Sign Up Now to create an account. Even if you have an existing Amazon account, you will still need a credit card and phone number during the setup process.
  3. Wait until you get an email confirming that your account has been set up.
  4. Go back to the homepage and click on My Account/Console -> AWS Management Console. You can now sign in.

Creating a Server

  1. Sign in.
  2. Click the EC2 tab.
  3. Click the Launch Instance Button.

    EC2 Tab

  4. Quicklaunch should be selected from the left column.
  5. Give your server a name.
  6. Make sure Create new Key Pair is selected and click Download to save the key.
  7. Make sure Amazon Linux 64-bit is selected.
  8. Click Continue.

    EC2 Tab

  9. Double check that the type is t1.micro. (Anything larger and you get charged.)
  10. Click Edit details.

    EC2 Tab

  11. Select Security Settings -> Security Groups.
  12. Select Create new Security Group.
  13. Give it a name and description.
  14. Add an SSH rule with source 0.0.0.0/0. By setting source to 0.0.0.0/0, any computer can access the server.
  15. Add an HTTP rule with source 0.0.0.0/0.
  16. Click Create.
  17. Click Save details.

    EC2 Tab

  18. Click Launch.
  19. Click Close.

Connecting to and Setting Up Your Server

  1. Make sure you are signed in and in the EC2 tab.
  2. Select Instances under INSTANCES in the left navigation bar.
  3. Click on your server.
  4. The box at the bottom of the page should be open to the Description tab. Note the Public DNS value towards the bottom of it.

    EC2 Tab

  5. If you are on a non-Windows system, open X11 for Mac or Terminal for Linux. Use the command line argument ssh -i /path/to/my/keyfile.pem ec2-user@ec2-##-##-##-###.compute-#.amazonaws.com, where /path/to/my/keyfile.pem is the path to the key file you downloaded and ec2-##-##-##-###.compute-#.amazonaws.com is the Public DNS value. Remember to put a space after -i and DO NOT put a space between ec2-user@ annd your Public DNS value.
  6. If you are using Windows, the process is a bit more complicated:
    • Download PuTTY and PuTTYgen if you do not already have it.
    • Open PuTTYgen by going to Start -> Programs -> WinSCP -> Key tools -> PuTTYgen.
    • Select Conversions -> Import Key and find your file.
    • Click Save private key. Name it something like myKeyPair, and make sure the type is *.ppk. You will get a warning, but just click Yes.
    • Close PuTTYgen and open PuTTY and go to Connection -> SSH -> Auth in the left navigation bar.
    • Click the Browse button near the bottom of the page and select your *.ppk file.
    • Go back to the Session page and save the configuration so you don't have to find the key every time you log in.
    • Now sign in as ec2-user@ec2-##-##-##-###.compute-#.amazonaws.com, where ec2-##-##-##-###.compute-#.amazonaws.com is the Public DNS value.
  7. Install the propriate packages on the server using the following commands (where 'password' is whatever you want your mysql password to be):
                sudo su
                yum install httpd
                yum install mysql-server mysql
                yum install php php-mysql
                service httpd start
                service mysqld start
                /usr/bin/mysqladmin -u root password 'password'
            
  8. Use the following commands to give yourself permission to upload your files to your server:
                cd ../../var/www
                chown ec2-user html/
            
  9. To make sure the server is working, type http://ec2-##-##-##-###.compute-#.amazonaws.com into your web browser, where ec2-##-##-##-###.compute-#.amazonaws.com is the Public DNS value. You should see a test page. If your browser times out, go to Security Groups in the left navigation bar on your AWS EC2 tab and make sure the security group you set up for your server has the http rule. If not, add it and don't forget to click the Apply Rule Changes button.

Uploading Your Files

  1. If you are on a non-Windows system, log out of your server by using the command exit until you are back to your local machine, and then use the command line argument scp -i /path/to/my/keyfile.pem /path/to/my/copyfile.txt ec2-user@ec2-##-##-##-###.compute-#.amazonaws.com:path/to/assignment/folder, where /path/to/my/keyfile.pem is the path to the key file you downloaded, ec2-##-##-##-###.compute-#.amazonaws.com is the Public DNS value, and /path/to/assignment/folder is the path to your assignment folder on your server. /path/to/assignment/folder should start with ../../var/www/html. If you just want to test a file to make sure your server is working, just use the path ../../var/www/html.
  2. If you are using Windows, the process is a bit more complicated:
    • Download WinSCP if you do not already have it.
    • Open WinSCP.
    • Set Host name to ec2-##-##-##-###.compute-#.amazonaws.com, where ec2-##-##-##-###.compute-#.amazonaws.com is the Public DNS value.
    • Set User name to ec2-user
    • Press the ... button at the end of the Private key file bar and find your *.ppk key file.
    • Click the Save button at the bottom of the window so you don't have to enter all of the information every time you log in.
    • Click Login.
    • Navigate to the html folder by going through the following folders: .. -> .. -> var -> www -> html. From here you should see your assignment folders if you have created them. If you want to test a file to make sure your server is working, just put it into this folder.

If You Have Trouble

Try some of the following:

  1. Make sure you have set up the SSH and HTTP rules with location 0.0.0.0/0.
  2. If you changed the SSH and HTTP rules, then make sure you not only clicked the Add Rule button, but also the Apply Rule Changes button.
  3. Make sure you chose the correct key when signing in.
  4. Make sure the name of your key and the names of all of the folders in the path to your key are one word.
  5. Make sure the path to your key is correct.
  6. Make sure you put a space after "-i" for ssh and scp.
  7. Sign in as root instead of ec2-user.
  8. Set the key permissions to 400 (only readable, and only by you).
  9. Make sure you are installing the packages on the server, not your local computer.
  10. Retype the installation commands.
  11. Make sure you include your key when doing the scp command.
  12. If you are using TextEdit, make sure you change the properties so that files are saved as plain text. You can find instructions for this online.

Props

This document is based on the tutorials and posts at imperialWicket, Cloud Computing Info, Coding This, and the AWS Forum.

Please email Jeffrey P. Bigham at jbigham@cs.rochester.edu with questions.

Valid XHTML 1.0 Transitional Valid CSS!