today’s topicstodd/cse... · 9extensible networking platform-cse 330 –creative programming and...

21
1 - CSE 330 – Creative Programming and Rapid Prototyping Today’s Topics Web Resources Amazon EC2 Linux Apache PHP Workflow and Tools 2 - CSE 330 – Creative Programming and Rapid Prototyping Course Wiki

Upload: others

Post on 06-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 11 - CSE 330 – Creative Programming and Rapid Prototyping

Today’s Topics

• Web Resources

• Amazon EC2

• Linux

• Apache

• PHP

• Workflow and Tools

Extensible Networking Platform 22 - CSE 330 – Creative Programming and Rapid Prototyping

Course Wiki

Page 2: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 33 - CSE 330 – Creative Programming and Rapid Prototyping

Piazza

• We are using Piazza as a forum to answer questions about the course

• Make sure you sign up at piazza.com and join the CSE 330 course discussion

Extensible Networking Platform 44 - CSE 330 – Creative Programming and Rapid Prototyping

Collaboration Policy

Page 3: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 55 - CSE 330 – Creative Programming and Rapid Prototyping

Amazon EC2

Extensible Networking Platform 66 - CSE 330 – Creative Programming and Rapid Prototyping

Using Amazon EC2 with LAMP

• LAMP – Linux

• The operating system running on your EC2 instance– Apache

• A web service running on your EC2 instance – MySQL

• A database service – PHP

• A programming language used to help with communication between the database, web server, and OS

Page 4: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 77 - CSE 330 – Creative Programming and Rapid Prototyping

Linux

• Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel

• It was created by Linus Torvalds

• It is Free and Open source

Extensible Networking Platform 88 - CSE 330 – Creative Programming and Rapid Prototyping

Unix? Linux? What about Windows?

• Unix is a computer operating system developed in 1969 by a group of AT&T employees at Bell Labs

• Linux is a popular Unix-like operating system along with others (FreeBSD, NetBSD, OpenBSD)– Runs on servers, desktops, laptops, cellphones

• We will use a particular distribution of Linux called AMI developed by Amazon for the cloud– Based on Red Hat Enterprise Linux (RHEL)

Page 5: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 99 - CSE 330 – Creative Programming and Rapid Prototyping

Using Linux

• Most of the commands we will issue involve using a terminal– See the wiki for examples of syntax

• Editing files is a necessity when administrating a Linux machine– Pick your favorite text editor

• vi• emacs• Nano (not recommended, but very easy to use)

Extensible Networking Platform 1010 - CSE 330 – Creative Programming and Rapid Prototyping

Various Linux Commands • Frequently used commands available in most shells:

– ls : to show the names of the file in the current directory– cd : change directory,

• e.g. cd / change to the root directory– cd .. change to the parent of that directory

– cp : copy one file to another• e.g. cp abc.txt xyz.txt copy abc.txt to xyz.txt

– rm : remove a file– man : ask for the manual (or help) of a command

• e.g. man cd ask for the manual of the command cd– pwd : show the name of the current directory– cat : to show the content of a text file

• e.g. cat abc.txt show the content of abc.txt– whoami : to show the username of the current user

Page 6: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 1111 - CSE 330 – Creative Programming and Rapid Prototyping

File System in Linux

/home/bob/SystemConfig

ls, cp, rm, ps

Extensible Networking Platform 1212 - CSE 330 – Creative Programming and Rapid Prototyping

Navigating in Linux Demo

Page 7: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 1313 - CSE 330 – Creative Programming and Rapid Prototyping

Types of User Accounts

• Preconfigured user accounts– Root

• Administrative account• Also called superuser• Can perform any operation on Linux system• Do not log in as root for normal work• Change temporarily to root user

Extensible Networking Platform 1414 - CSE 330 – Creative Programming and Rapid Prototyping

Types of User Accounts (continued)

• su command – Temporarily changes access rights to those of

another user– Without any parameters

• Change to root account– Hyphen after su command

• Causes command to run login scripts • Places you in login directory of user

Page 8: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 1515 - CSE 330 – Creative Programming and Rapid Prototyping

Types of User Accounts (continued)

• Preconfigured user accounts– Regular user accounts

• Users who log in at keyboard and use Linux system• Commonly associated with named individuals

– Special user account• Used by Linux programs• Created during installation of Linux• Vary depending on services installed

Extensible Networking Platform 1616 - CSE 330 – Creative Programming and Rapid Prototyping

Linux Groups

• Group – Collection of user accounts– Can be collectively granted access to files and

directories• Each user in Linux is assigned to primary group• /etc/group file

– Lists members of each defined group

Page 9: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 1717 - CSE 330 – Creative Programming and Rapid Prototyping

User and Group Files

• /etc/passwd– Stores user account information– Password information not stored in this file– Contents include:

• User account name• Password• User ID number (UID)• Group ID number (GID)• User�s real name• Home directory• Default shell

Extensible Networking Platform 1818 - CSE 330 – Creative Programming and Rapid Prototyping

File Permissions

• Files and directories have– Owner– Group

• Linux determines who can access file or directory based on: – Who owner is – Which group is assigned to object

• File permissions define access granted to file or directory

Page 10: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 1919 - CSE 330 – Creative Programming and Rapid Prototyping

File Permissions (continued)

• Access mode• Permissions

– Read permission (r)– Write permission (w)– Execute permission (x)

• Permissions can be assigned by:– User permissions– Group permissions– Other permissions

Extensible Networking Platform 2020 - CSE 330 – Creative Programming and Rapid Prototyping

Installing software in Linux• Most software that we use in this course is NOT installed

by default

• Use a package manager– Amazon EC2 running Ubuntu (Debian) uses apt

• “sudo apt-get install my-new-software”– AMI Linux distribution uses yum package manager

• “sudo yum install my-new-software”– Other distros might have a different package manager

• zypp (openSUSE), urpmi (Mandriva)

• Get the source– Generally you can download the source code and build the

application binaries on your machine• Download tarbar• “./config; make; make install”

Page 11: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 2121 - CSE 330 – Creative Programming and Rapid Prototyping

Getting Stuck• Look at the wiki

– http://classes.engineering.wustl.edu/cse330/index.php/Linux

• Use the �man� commands– “man cp”

• Ask Google– http://bit.ly/PNGfHP

• Ask a TA

Extensible Networking Platform 2222 - CSE 330 – Creative Programming and Rapid Prototyping

Amazon Private Key

• Be sure to backup your private key

• Considered a huge security risk having multiple copies of a private key – However, being unable to access your machine is worse

• If you are unable to connect you may be able to restore your VM with an EBS snapshot

Page 12: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 2323 - CSE 330 – Creative Programming and Rapid Prototyping

SSH Keys

• SSH keys provide a more secure way of logging into EC2 with SSH than using a password alone

• Generating a key pair provides you with two long string of characters: a public and a private key.

• You can place the public key on any server, and then unlock it by connecting to it with a client that already has the private key.

• When the two match up, the system unlocks without the need for a password

• You can increase security even more by protecting the private key with a passphrase.

• The wiki walks through how to generate the SSH key pair on your PC– You will then copy the public key to your EC2 instance

• We will also use the key pair for other applications to help us copy files and provide version control

Extensible Networking Platform 2424 - CSE 330 – Creative Programming and Rapid Prototyping

More Linux and EC2 StuffDemo

Page 13: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 2525 - CSE 330 – Creative Programming and Rapid Prototyping

Module 2 - Apache

l Apache Software Foundation (ASF) is a non-profit organization that develops several high-quality open-source programs

l Apache HTTP (Web) server is one such program

Extensible Networking Platform 2626 - CSE 330 – Creative Programming and Rapid Prototyping

Apache HTTP (Web) Server

l The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP serverl Used for modern operating systems including UNIX

and Windows XP

l Apache has been the most popular web server since April 1996 when it passed NCSA

l Provides a secure, efficient and extensible serverl Using HTTP services in sync with the current HTTP

standards.

Page 14: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 2727 - CSE 330 – Creative Programming and Rapid Prototyping

Apache HTTP (Web) Server

l Application that runs on our Linux server

l We start and stop this application on our server as an Administrator (root)

Extensible Networking Platform 2828 - CSE 330 – Creative Programming and Rapid Prototyping

Module 2 – HTML,CSS, and PHP

• Module 2 contains 2 components– Individual Assignment– Group Assignment (comprised of 2 students)

• Both are due on Wed Sept 11th by 11:30 AM– Do not wait until the last minute to complete this lab

• Read the Wiki before attempting the lab!

Page 15: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 2929 - CSE 330 – Creative Programming and Rapid Prototyping

What is PHP?• PHP stands for PHP Hypertext Processing

– Recursive acronym (like GNU or WINE)

• A general purpose scripting (programming) language especially suited for Web Development

• Very useful for creating dynamic web pages

Extensible Networking Platform 3030 - CSE 330 – Creative Programming and Rapid Prototyping

Cost Benefits

• PHP is free– Open source code means that the entire PHP

community will contribute towards bug fixes.

• There are several add-on technologies (libraries) for PHP that are also free

Page 16: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 3131 - CSE 330 – Creative Programming and Rapid Prototyping

Why is PHP used?

• Cross Platform– Runs on almost any Web server or multiple

operating systems

– Web Servers: Apache, Microsoft IIS

– Operating Systems: Linux, OS X, Windows

Extensible Networking Platform 3232 - CSE 330 – Creative Programming and Rapid Prototyping

Getting StartedSimple HTML Page with PHPThe following is a basic example to output text using PHP

<!DOCTYPE html> <html><head><title>My First PHP Page</title></head><body><?phpecho "Hello World!";?></body></html>

Copy the code onto your web server and save it as �test.php�. You should see �Hello World!� displayed.

Notice that the semicolon is used at the end of each line of PHP code to signify a line break. Like HTML, PHP ignores whitespacebetween lines of code. (An HTML equivalent is <BR>)

Page 17: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 3333 - CSE 330 – Creative Programming and Rapid Prototyping

Extensible Networking Platform 3434 - CSE 330 – Creative Programming and Rapid Prototyping

PHP

DEMO

Page 18: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 3535 - CSE 330 – Creative Programming and Rapid Prototyping

Getting Started

Using conditional statementsConditional statements are very useful for displaying specific content to the

user. The following example shows how to display content according to the day of the week.

<?php$today_dayofweek = date(“w”);if ($today_dayofweek == 4){

echo “Today is Thursday!”; }else{

echo “Today is not Thursday.”;}?>

Extensible Networking Platform 3636 - CSE 330 – Creative Programming and Rapid Prototyping

Getting Started

Using conditional statementsThe if statement checks the value of $today_dayofweek

(which is the numerical day of the week, 0=Sunday… 6=Saturday)

If it is equal to 4 (the numeric representation of Thurs.) it will displayeverything within the first { } bracket after the �if()�.

If it is not equal to 4, it will display everything in the second { } bracket after the �else�.

<?php$today_dayofweek = date(“w”);if ($today_dayofweek == 4){

echo “Today is Thursday!”; }else{

echo “Today is not Thursday.”;}?>

Page 19: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 3737 - CSE 330 – Creative Programming and Rapid Prototyping

HTML Form Example

<!DOCTYPE HTML><head> <title> My HTML Form </title></head><body><form name="input" action="htmlFormActionGet.php” method="get">

Username: <input type="text" name="user" />

<input type="submit" value="Submit" />

</form> </body></form>

<?php$userName = $_GET["user"];echo "Hello " . $userName;echo "<br>";echo "Hello Again $userName";?>

htmlFormActionGet.php

formExampleGet.html

Extensible Networking Platform 3838 - CSE 330 – Creative Programming and Rapid Prototyping

Forms and PHP

• The PHP language can be used to make pages that �do something�– You can use PHP to write complete programs, but...

– Usually you just use snippets of PHP here and there throughout your Web page

– PHP code snippets can be attached to various form elements• For example, you might want to create a super simple web calculator (like

we do in Module 2)

Page 20: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 3939 - CSE 330 – Creative Programming and Rapid Prototyping

Filter Input; Escape Output (FIEO)• Filtering Input

– You should check input to verify it is what you expect• Cast variables to expected types • Pass input through validation scripts (regular expressions – Module 4) <?php

//Cast a number to a float or int$amount = (float) $_POST[‘amount’];

?>

• Escaping Output– Remove, nullify, or “escape” the output of characters that may

have special meaning in another language (HTML)<?php$str= “If a<b and b<c then a<c.”;

//Convert special characters to HTML entities before outputtingecho htmlentities($str);?>

• Consult the wiki for more information

Extensible Networking Platform 4040 - CSE 330 – Creative Programming and Rapid Prototyping

Workflow and Tools

Page 21: Today’s Topicstodd/cse... · 9Extensible Networking Platform-CSE 330 –Creative Programming and Rapid Prototyping 9 Using Linux •Most of the commands we will issue involve using

Extensible Networking Platform 4141 - CSE 330 – Creative Programming and Rapid Prototyping

Software Tools in Urbauer Lab

• Cygwin– Linux shell for Windows

• Git– Version Control Software

• SourceTree – GUI for Git

• Komodo – Multi-Language Editor

• Filezilla – SFTP Tool for copying files to and from EC2

Extensible Networking Platform 4242 - CSE 330 – Creative Programming and Rapid Prototyping

Demo of Additional Tools