Programming Fundamentals I: Ryan Waliany

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Programming Fundamentals I

Ryan Waliany @rwaliany

General Assembly Handout August 2nd, 2012


1

Getting Started
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that enables you to launch and manage Linux/UNIX and Windows server instances in Amazons data centers. You will be using the AWS Management Console which is a point-and-click web-based interface.

Sign Up for EC2


To sign up for EC2, visit http://aws.amazon.com/console and click sign up now. Follow the on-screen instructions which involves entering a credit card and receiving a phone call to verify your identity with a PIN. Important You will only be billed for the services that you use. You are allowed one instance in the Free Usage Tier for no cost. You are billed from the time you launch the instance until the instance is no longer running.

Launch Instance

3 1. Sign in to the AWS Management Console and open the Amazon EC2 console at http://console.aws.amazon.com/ec2/ 2. From the Amazon EC2 console dashboard, click Launch Instance. 3. Select a name for your instance, such as Web Server. 4. Create a key pair by entering a name and clicking download. Save the le to a safe location as it is a key to your house on the internet. 5. Under the Quick Launch Wizard, select Ubuntu Server 12.04 LTS and click continue.

Important Verify that you see t1.micro as the machine type since this is the only server size that qualies for the Free Usage Tier.

Connecting to your Instance


Now that youve started up your rst EC2 Instance. You can click the Instances tab on the left-hand side to see the status of your machine. Your machine should have the state pending and after two minutes this status should change to running.

1. To connect to your instance, right-click the server row and click Connect.

2. Select Connect from your browser using the Java SSH (Secure Shell) Client. You will be asked for the username, which you should change to ubuntu and the private key path. The private key path will be wherever you saved your key.

3. Write down your hostname. In the screenshot above, the hostname is ec2-50-112-39-111.us-west-2.compute.amazonaws.com.

Congratulations! If youve reached this step, you have successful started your rst Linux server and connected to it!

Conguring your Instance


Introduction to Shell
A shell is an interface for users of an operating system which provides access and operations to les and other parts of the kernel. You should have a secure shell open connected to your EC2 instance. Shell Commands ls <directory> - lists les and folders in a directory. If no directory argument are provided, it will list the contents of the current directory. cd <directory> - change current working directory. If no directory argument are provided, it will list the change the working directory to your home directory. cp <source> <destination> - copy le from the source to the destination location.

6 mv <source> <destination> - move le from the source to the destination location. rm <le> - remove le. sudo <command> - execute a command with administrator powers. sudo apt-get update - updates the list of packages for installation as administrator. sudo apt-get install <package> - installs a package as administrator. nano <le> - text editor program similar to notepad in shell.

Installing PHP5 and Apache2

To get started, type the following commands (in bold) into the shell followed by enter. sudo apt-get update sudo apt-get install apache2 php5 - It calculates the dependencies and list of all packages to be installed. Type Y to proceed followed by an enter.

Creating your rst website

In this section, we will change our current working directory to the directory that contains the website. We will open the website in a text editor and we will add our own message to it! Please execute the following commands in bold.

cd /var/www - change the directory to /var/www

ls - check to see that index.html is present

sudo nano index.html - open up the text editor for index.html. Add the text <p>I just wrote my rst line of html</p> just before </body>. Press ctrl and x at the same time, then press y, then hit enter. This will save and exit the nano program.

Changing your security group

Your website should be up and running, but you wont be able to access it from your home computer. This is because Amazon, by default, has an extremely strict internet policy (rewall). In your web browser on the Amazon Web Console screen, perform the following actions: Click Security Groups on the left-hand side Click the quick-launch policy. In the bottom tab, select Inbound. Enter 80 in the Port Range eld, click Add Rule, and then click Apply Rule Change. To see your website, enter your hostname in a web browser and it should work!

Creating your rst web program in PHP

In this section, we will change our HTML le to a PHP le by simply renaming it. Once weve renamed it, we will edit the le again using nano and add some PHP code. ls - check to see that index.html is present sudo mv index.html index.php - move index.html to index.php ls - check to see that index.php is present sudo nano index.php - open up the text editor for index.php. Add the text <?php echo I just wrote my rst computer program!; ? > just before </body>. Press ctrl and x at the same time, then press y, then hit enter. This will save and exit the nano program. To see your rst computer program, refresh your web browser!

Additional Resources
http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/Welcome.html http://php.net/manual/en/tutorial.php

You might also like