Intro to LAMP, Web Architecture, and HTTP

CS418 - Web Programming - Spring 2015

Old Dominion University

Mat Kelly (mkelly@cs.odu.edu)
http://www.cs.odu.edu/~mkelly/cs418

Slides adapted from version by Dr. Michele C. Weigle

LAMP

  • Linux - operating system
  • Apache - web server
  • MySQL - relational database
  • PHP - server-side scripting

Why LAMP?

  • Free and Open Source Software (FOSS)
  • Components are theoretically swappable
    • e.g., another FOSS server-side script language can be used in place of PHP
  • No restrictions on derivative software
* Camel icon a trademark of O'Reilly Media
Stallman

The Web

  • User agent (client)
    • Frequently a Web Browser
    • Alternatively, a script or command-line tool (wget, curl)

The Web

  • User agent (client)
    • Frequently a Web Browser
    • Alternatively, a script or command-line tool (wget, curl)
  • Web Server (server)
    • Handles requests from clients

Web Terminology

  • Uniform Resource Identifier (URI)
    • addresses web pages
  • Web pages consist of "objects"
    • Mostly HTML pages
    • Also includes images, scripts, other objects

URI, URL, and URN

  • Uniform Resource Identifier (URI)
    • http://www.ietf.org/rfc/rfc2396.txt
    • news:comp.infosystems.www.servers.unix
    • http://foo.com/page.html#section2
  • Uniform Resource Locator (URL)
    • http://foo.com/page.html
  • Uniform Resource Name (URN)
    • Unambiguous identifier
      • defines identity (not necessarily location)
    • urn:isbn:978-0321751041
    • foo.com/page.html#section2
URI, URL, URN Euler

Term Definitions: RFCs

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Note that the force of these words is modified by the requirement level of the document in which they are used.

1. MUST This word, or the terms "REQUIRED" or "SHALL", mean that the definition is an absolute requirement of the specification.

2. MUST NOT This phrase, or the phrase "SHALL NOT", mean that the definition is an absolute prohibition of the specification.

3. SHOULD This word, or the adjective "RECOMMENDED", mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

4. SHOULD NOT This phrase, or the phrase "NOT RECOMMENDED" mean that there may exist valid reasons in particular circumstances when the particular behavior is acceptable or even useful, but the full implications should be understood and the case carefully weighed before implementing any behavior described with this label.

5. MAY This word, or the adjective "OPTIONAL", mean that an item is truly optional. One vendor may choose to include the item because a particular marketplace requires it or because the vendor feels that it enhances the product while another vendor may omit the same item. An implementation which does not include a particular option MUST be prepared to interoperate with another implementation which does include the option, though perhaps with reduced functionality. In the same vein an implementation which does include a particular option MUST be prepared to interoperate with another implementation which does not include the option (except, of course, for the feature the option provides.)

RFC 2616 - HTTP/1.1

  • Describes Hypertext Transfer Protocol structure & dynamics
  • Extends RFC 1945 (HTTP/1.0) and RFC 2068 (HTTP/1.1, now obsolete)
  • Newer definition for the Web describes URIs, protocols, and formats
    • http://www.w3.org/TR/webarch/

RFC 2616 Examples

§ 10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows...that an old resource is permanently unavailable and has no forwarding address
§ 10.3.2 301 Moved Permanently
The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs
§ 10.2.1 200 OK
The request has succeeded. The information returned with the response is dependent on the method used in the request
§ 10.4.6 405 Method Not Allowed
The method specified in the Request-Line is not allowed for the resource identified by the Request-URI.

URI Schemes

  foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose
  \_/   \_______________/ \_________/ \__/            \___/ \_/ \______________________/ \__/
   |           |               |       |                |    |            |                |
   |       userinfo           host    port              |    |          query          fragment
   |    \________________________________/\_____________|____|/ \__/        \__/
 scheme                 |                          |    |    |    |          |
  name              authority                      |    |    |    |          |
   |                                             path   |    |    interpretable as keys
   |                                                    |    |
   |    \_______________________________________________|____|/       \____/     \_____/
   |                         |                          |    |          |           |
 scheme              hierarchical part                  |    |    interpretable as values
  name                                                  |    |
   |            path               interpretable as filename |
   |   ___________|____________                              |
  / \ /                        \                             |
  urn:example:animal:ferret:nose               interpretable as extension

                path
         _________|________
 scheme /                  \
  name  userinfo  hostname       query
  _|__   ___|__   ____|____   _____|_____
 /    \ /      \ /         \ /           \
 mailto:username@example.com?subject=Topic
 

source: http://en.wikipedia.org/wiki/URI_scheme

Important Web Architecture Terms

  • URIs identify Resources
  • Representations represent Resources
  • When URIs are dereferenced, they return representations (i.e., a resource is never returned)
  • Different representations may be returned for the same URI (e.g., English vs. French version)
Web architecture

W3C Web Architecture

The tools we have to solve the interoperability problems are Resource, URI, and Representation

URI diagram

Content Negotiation Examples

  • Accept-Language: en; q=1.0, de; q=0.5
  • Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
  • Accept-Datetime: Wednesday, 14 January 2015 15:15:00 GMT

HTTP Overview

  • HTTP uses TCP
    • Browser initiates TCP connection to server (on port 80)
  • HTTP messages exchanged between browser and web server
  • HTTP is stateless
    • server maintains no information about past browser requests

HTTP Example

  1. User enters URI http://www.cs.odu.edu/~mkelly/
    • Referenced object contains HTML text and references images
  2. Browser sends an HTTP GET request to www.cs.odu.edu
  3. Server retrieves and sends the client the HTML file
  4. Browser reads the file and sequentially makes separate requests for each embedded image.

HTTP Request Message Format

  • HTTP messages are ASCII (human-readable)
$ curl -iv http://www.cs.odu.edu/~mkelly/
  • CLIENT→Server
  • * Connected to www.cs.odu.edu (128.82.4.2) port 80 (#0)
  • > GET /~mkelly/ HTTP/1.1
  • > User-Agent: curl/7.37.1
  • > Host: www.cs.odu.edu
  • > Accept: */*
  • CLIENT←SERVER
  • < HTTP/1.1 200 OK
  • < Server: nginx
  • < Date: Wed, 14 Jan 2015 00:46:19 GMT
  • < Content-Type: text/html
  • < Transfer-Encoding: chunked
  • < Connection: keep-alive
  • < Vary: Accept-Encoding
  • <!DOCTYPE html>
  • <html>
  • <head>

HTTP Methods

  • GET, HEAD
  • TRACE
    • What methods are defined on this URI?
  • DELETE
    • Rarely supported for most URIs
  • PUT
    • Rarely supported. Equivalent to Unix $ echo "hello world" > temp.txt
  • POST
    • Frequently used for passing credentials.

More HTTP Methods!

MethodRFCSupported (Count)Percentage
GET26162289956.029%
HEAD26162287955.980%
OPTIONS26162272655.606%
POST26161649740.365%
TRACE26161494636.570%
DELETE26167351.798%
PUT26166961.703%
CONNECT26164221.033%
PROPFIND251812263.000%
COPY251812182.980%
LOCK251811962.926%
UNLOCK251811902.912%
MOVE25185421.326%
PROPPATCH25185361.311%
MKCOL25185231.280%
MKDIR181360.015%
RMDIR181360.015%
PATCH57894181.023%
REPORT325310.002%
ACL374410.002%
SEARCH53236111.495%
INDEXUnknown60.015%
NNOCUnknown10.002%

from S. Alam "Support for Various HTTP Methods on the Web"