<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://classes.engineering.wustl.edu/cse330/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jasonren</id>
	<title>CSE330 Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://classes.engineering.wustl.edu/cse330/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jasonren"/>
	<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Special:Contributions/Jasonren"/>
	<updated>2026-11-15T18:17:13Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=2797</id>
		<title>Module 5</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=2797"/>
		<updated>2021-03-11T20:23:28Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In Module 5, you will learn JavaScript, the dominant client-side web language.  JavaScript is the third and final programming language you will learn in CSE 330.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 5.&lt;br /&gt;
&lt;br /&gt;
'''Warning:'''&lt;br /&gt;
&lt;br /&gt;
''This module takes students a while. It is strongly recommended that you start early and ask questions as they come up.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[JavaScript]]&lt;br /&gt;
* [[AJAX and JSON]]&lt;br /&gt;
* [[jQuery]]&lt;br /&gt;
* [[Web Application Security, Part 3]]&lt;br /&gt;
* [[FAQ - Mod 5]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
'''''IMPORTANT:'' Both of the individual assignments must be completed ''without'' using a JavaScript library like jQuery.'''  However, you may use jQuery for the group portion.&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add, subtract, multiply, divide).&lt;br /&gt;
* JavaScript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
*: '''Tip 1:''' Consider using either the ''change'' or the ''keyup'' event on the text fields, and either the ''change'' or the ''click'' event on the radio buttons.&lt;br /&gt;
*: '''Tip 2:''' Re-read [[JavaScript|the JavaScript guide]] if you need help figuring our how to bind callback functions to events, or how to determine which radio button is currently selected.  (There are examples for both of these!)&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
'''Important:''' It is best practice to fully separate the content, appearance, and behavior.  In previous modules, you may have lost points for using HTML tags that change the appearance of things &amp;lt;nowiki&amp;gt;(like &amp;lt;center&amp;gt; and &amp;lt;font&amp;gt;).&amp;lt;/nowiki&amp;gt;  In this module, make sure that you define your event listeners in JavaScript as in &amp;lt;code&amp;gt;document.getElementById(&amp;quot;xyz&amp;quot;).addEventListener(...)&amp;lt;/code&amp;gt; and '''''not''''' in the HTML like &amp;lt;code&amp;gt;&amp;lt;button onclick=&amp;quot;badExample();&amp;quot;&amp;gt;Bad Example&amp;lt;/button&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your HTML document.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' https://classes.engineering.wustl.edu/cse330/content/weather_json.php&lt;br /&gt;
#* '''IMPORTANT:''' Under normal circumstances, AJAX requests ''cannot'' be performed cross-domain for security reasons.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances, or from localhost.  '''You will therefore need to upload your code to your EC2, or access it via localhost, in order for the AJAX requests to work.'''  This means that you cannot, for example, complete this part of the individual portion in JSFiddle.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentLoaded event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentLoaded&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
# In addition, add a button that runs your ''fetchWeather'' function when clicked.  This should update your widget with the current weather conditions.&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: https://classes.engineering.wustl.edu/cse330/content/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
One place to get the images is from here: &amp;lt;nowiki&amp;gt;http://us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
You are encouraged to use the advanced version control practices you learned in Module 5 when completing this assignment.&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including Ext JS, so long as that JavaScript library does not defeat the purpose of the assignment. If you have questions about this, ask. In particular, libraries like FullCalendar are unacceptable.&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
We have also written some functions to help you get started: [[JavaScript Calendar Library]]&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Server Side Language ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Additionally, you may use a database of your choice.  MySQL is probably the logical choice since you have been using it since Module 2, but you are free to explore other databases if you like.&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from module 3 to get started.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
*: Your AJAX should not ask the server for events from a certain username.  Instead, your AJAX should ask the server for events, and the server should respond with the events for only the currently-logged-in user (from the session).  Can you think of why?&lt;br /&gt;
* Registered users can edit and delete their own events, but not the events of others.&lt;br /&gt;
*: Again, the server should edit and delete events based on the username present in the session, not based on a username or event ID provided by the user.  (If it deletes only based on an Event ID, an attacker could feed any arbitrary Event ID to your server, even if he/she didn't own that event.)&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  Be careful when transmitting data over JSON that will be reflected in an event title!  (Note: JSON data should be sanitized on the client side, not the server side.)&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors or warnings through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 100 points in total.&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0. ''' &lt;br /&gt;
&lt;br /&gt;
If you do not include a link to your individual and group portion running on your instance in the respective README.md, you will receive a 0 for the missing portion&lt;br /&gt;
&lt;br /&gt;
_________&lt;br /&gt;
&lt;br /&gt;
# '''JavaScript Calculator (10 Points):'''&lt;br /&gt;
#* Calculator successfully adds, subtracts, multiplies, and divides numbers (3 points)&lt;br /&gt;
#* The result is automatically computed when a value in either field is changed (3 points)&lt;br /&gt;
#* Calculator is written entirely in pure, conventional JavaScript with no external libraries (4 points)*&lt;br /&gt;
#*: ''Note: be sure to fully separate content, appearance, and behavior.  This means that you should '''not''' use the event attributes on the HTML elements like onclick, onchange, and onkeyup.''&lt;br /&gt;
# '''Weather Widget (15 Points):'''&lt;br /&gt;
#* Widget performs an AJAX request to fetch the current weather (4 points)&lt;br /&gt;
#* The HTML template is filled with the correct information, including an image (4 points)&lt;br /&gt;
#* Button to reload the weather widget (2 points)&lt;br /&gt;
#* Widget is written entirely in pure, conventional JavaScript with no external libraries (5 points)*&lt;br /&gt;
# '''AJAX Calendar (60 Points):'''&lt;br /&gt;
#* '''''Calendar View (10 Points):'''''&lt;br /&gt;
#** The calendar is displayed as a table grid with days as the columns and weeks as the rows, one month at a time (5 points)&lt;br /&gt;
#** The user can view different months as far in the past or future as desired (5 points)&lt;br /&gt;
#* '''''User and Event Management (25 Points):'''''&lt;br /&gt;
#** Events can be added, modified, and deleted (5 points)&lt;br /&gt;
#** Events have a title, date, and time (2 points)&lt;br /&gt;
#** Users can log into the site, and they cannot view or manipulate events associated with other users (8 points)&lt;br /&gt;
#**: ''Don't fall into the Abuse of Functionality trap!  Check user credentials on the server side as well as on the client side.''&lt;br /&gt;
#** All actions are performed over AJAX, without ever needing to reload the page (7 points)&lt;br /&gt;
#** Refreshing the page does not log a user out (3 points)&lt;br /&gt;
#* '''''Best Practices (20 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (2 points)&lt;br /&gt;
#** If storing passwords, they are stored salted and hashed (2 points)&lt;br /&gt;
#** All AJAX requests that either contain sensitive information or modify something on the server are performed via POST, not GET (3 points)&lt;br /&gt;
#** Safe from XSS attacks; that is, all content is escaped on output (3 points)&lt;br /&gt;
#** Safe from SQL Injection attacks (2 points)&lt;br /&gt;
#** CSRF tokens are passed when adding/editing/deleting events (3 points)&lt;br /&gt;
#** Session cookie is HTTP-Only (3 points)&lt;br /&gt;
#** Page passes the W3C validator (2 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)'''&lt;br /&gt;
#* '''Additional Calendars Features (worth 15 points):''' Develop some additional features for the calendar, a few examples are provided below.&lt;br /&gt;
#**  Users can tag an event with a particular category and enable/disable those tags in the calendar view. (5 points)&lt;br /&gt;
#**  Users can share their calendar with additional users. (5 points)&lt;br /&gt;
#**  Users can create group events that display on multiple users calendars (5 points)&lt;br /&gt;
#*  '''Make sure to save a description of your creative portion, and a link to your server in your README.md file.'''&lt;br /&gt;
''* These points can be earned only if at least 3 other points have been earned in that category.  This is to prevent these points from being &amp;quot;free.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 5]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=2790</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=2790"/>
		<updated>2021-02-17T16:37:14Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Introduction to MySQL]]&lt;br /&gt;
* [[MySQL Schema and State]]&lt;br /&gt;
* [[PHP and MySQL]]&lt;br /&gt;
* [[Web Application Security, Part 2]]&lt;br /&gt;
* [[FAQ - Mod 3]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so. Instructions to install both can be found on the [[Introduction to MySQL]] page.&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL#Managing Databases]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID for the primary key? The ID numbers are sometimes reused across schools. For instance, department 33 in The College of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table). There will never be more than 1,000 grades per student.&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal(5,2)'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
* students: https://classes.engineering.wustl.edu/cse330/content/students_data.txt&lt;br /&gt;
* courses: https://classes.engineering.wustl.edu/cse330/content/courses.txt&lt;br /&gt;
* departments: https://classes.engineering.wustl.edu/cse330/content/departments_data.txt&lt;br /&gt;
* grades: https://classes.engineering.wustl.edu/cse330/content/grades_data.txt&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert entries for CSE 330S, CSE 131, and CSE 260M.&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below. &lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 35.5 in CSE 330S&lt;br /&gt;
#*** 0 in CSE 131&lt;br /&gt;
#*** 95 in CSE 260M&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100 in CSE 330S&lt;br /&gt;
#*** 90.5 in CSE 131&lt;br /&gt;
#*** 94.8 in CSE 260M&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 75 in CSE 330S&lt;br /&gt;
#*** 37 in CSE 131&lt;br /&gt;
#*** 45.5 in CSE 260M&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please Running the following &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; queries, then copy the output to a text file of the form &amp;lt;code&amp;gt;query1.txt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;query2.txt&amp;lt;/code&amp;gt;, and so on, and commit them with the rest of your repository (be sure to include your query command and the entire response, including the number of results found). For each query, only the requested columns should be present. You will receive 0 points for any query that includes additional columns.&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the College of Arts &amp;amp; Sciences (school code &amp;lt;code&amp;gt;L&amp;lt;/code&amp;gt;).&lt;br /&gt;
# The names, student IDs, and CSE330 grades of all students who are in CSE330S.&lt;br /&gt;
#: '''Note:''' This query should involve joins.  You don't need to use any aggregation functions.&lt;br /&gt;
# The names, e-mails, and average grades of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the &amp;lt;code&amp;gt;HAVING&amp;lt;/code&amp;gt; keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of only his student ID, e-mail address, and average grade.&lt;br /&gt;
#: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
#: '''Note:''' Your query must look for students with the name &amp;quot;Jack Johnson&amp;quot; instead of hard-coding the student ID.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your Git repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
* https://news.ycombinator.com/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit story commentary.&lt;br /&gt;
*: A link can be associated with each story, and they should be stored in a separate database field from the story.&lt;br /&gt;
*: For example, a story that included a link could look like the following:&lt;br /&gt;
*:: Title: Check out this cool search engine I found!&lt;br /&gt;
*:: Body: This search engine that I found has been very helpful with all of my homework assignments. Searching my error messages helps me debug.&lt;br /&gt;
*:: Link: http://google.com&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit and delete their stories and comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and links).&lt;br /&gt;
* Creative Portion.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
No application is finished until much thought is put into web security and best practice.  Throughout this course, we heavily emphasize the dogma of [https://mirrors.meiert.org/coderesponsibly.org/ responsible] coding.&lt;br /&gt;
&lt;br /&gt;
Read this week's Web Application Security guide: [[Web Application Security, Part 2]].  In particular, your project needs to:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure against SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''Your passwords need to be securely hashed salted''' to prevent rainbow table attacks.&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''You should check all preconditions on the server side''' to prevent Abuse of Functionality attacks.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''Your page should validate''' with no errors or warnings through the W3C validator.&lt;br /&gt;
* '''Filter Input and Escape Output''', but not the other way around.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 100 points total.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0. ''' &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''If you do not include a link to your group portion running on your instance in your group portion README.md, you will receive a 0 for the group portion.''' &lt;br /&gt;
________&lt;br /&gt;
&lt;br /&gt;
# '''MySQL Queries (25 Points):'''&lt;br /&gt;
#* A MySQL server is running on your instance. Put a screenshot in your repository of your terminal connected to your MySQL server. ( (2 points)&lt;br /&gt;
#* Tables' fields, including data types and foreign keys, are correct (8 points)&lt;br /&gt;
#*: ''Note: To demonstrate the structure of your tables, you should commit a text file containing the output of the &amp;lt;code&amp;gt;SHOW CREATE TABLE&amp;lt;/code&amp;gt; command '''for each table.''' Each table's file should have a name of the form &amp;lt;code&amp;gt;tablename.sql&amp;lt;/code&amp;gt; (e.g. &amp;lt;code&amp;gt;students.sql&amp;lt;/code&amp;gt;).''&lt;br /&gt;
#* The output of each of the five queries is correct. (3 points each)&lt;br /&gt;
#*: ''Note: To demonstrate the output of your queries, text files containing the 'entire' result (including the query and number of records found) of running each query should committed to Github. The file for query 1 should be named &amp;lt;code&amp;gt;query1.txt&amp;lt;/code&amp;gt;, the file for query 2 should be named &amp;lt;code&amp;gt;query2.txt&amp;lt;/code&amp;gt;, and so on.''&lt;br /&gt;
# '''News Site (60 Points):'''&lt;br /&gt;
#* '''''User Management (20 Points):'''''&lt;br /&gt;
#** A session is created when a user logs in (3 points)&lt;br /&gt;
#** New users can register (3 points)&lt;br /&gt;
#** Passwords are hashed, salted, and checked securely (3 points)&lt;br /&gt;
#**: ''Note: You will receive 0 points for this section if you use the &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;===&amp;lt;/code&amp;gt; operators to compare password hashes, or if you use the &amp;lt;code&amp;gt;crypt&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;md5&amp;lt;/code&amp;gt; functions at any point.''&lt;br /&gt;
#** Users can log out (3 points)&lt;br /&gt;
#** A user can edit and delete his/her own stories and comments but cannot edit or delete the stories or comments of another user (8 points)&lt;br /&gt;
#* '''''Story and Comment Management (20 Points):'''''&lt;br /&gt;
#** Relational database is configured with correct data types and foreign keys (4 points)&lt;br /&gt;
#*: ''Note: To demonstrate the structure of your database, you should commit a 'single' text file containing the output of the &amp;lt;code&amp;gt;SHOW CREATE TABLE&amp;lt;/code&amp;gt; command '''for all tables in your database,''' called &amp;lt;code&amp;gt;tables.sql&amp;lt;/code&amp;gt;. This one file should contain the output for all of your tables.&lt;br /&gt;
#** Stories can be posted (3 points)&lt;br /&gt;
#** A link can be associated with each story, and is stored in a separate database field from the story (3 points)&lt;br /&gt;
#** Comments can be posted in association with a story (4 points)&lt;br /&gt;
#** Stories can be edited and deleted (3 points)&lt;br /&gt;
#** Comments can be edited and deleted (3 points)&lt;br /&gt;
#**: ''Note: Although there are only 6 points allocated for editing/deleting in this section, there are 8 more points at stake in the User Management section that cannot be earned unless editing/deleting is implemented.  Implementing editing but not deleting, or vice-versa, will result in earning half the points.''&lt;br /&gt;
#* '''''Best Practices (15 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (3 points)&lt;br /&gt;
#** Safe from SQL Injection attacks (2 points)&lt;br /&gt;
#** Site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C HTML and CSS validators (2 points)&lt;br /&gt;
#** CSRF tokens are passed when creating, editing, and deleting comments and stories (5 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** Names and Student IDs of all the group members&lt;br /&gt;
#** A link to your homepage of the site&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=2789</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=2789"/>
		<updated>2021-02-12T20:41:56Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Introduction to MySQL]]&lt;br /&gt;
* [[MySQL Schema and State]]&lt;br /&gt;
* [[PHP and MySQL]]&lt;br /&gt;
* [[Web Application Security, Part 2]]&lt;br /&gt;
* [[FAQ - Mod 3]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so. Instructions to install both can be found on the [[Introduction to MySQL]] page.&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL#Managing Databases]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID for the primary key? The ID numbers are sometimes reused across schools. For instance, department 33 in The College of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table). There will never be more than 1,000 grades per student.&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal(5,2)'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
* students: https://classes.engineering.wustl.edu/cse330/content/students_data.txt&lt;br /&gt;
* courses: https://classes.engineering.wustl.edu/cse330/content/courses.txt&lt;br /&gt;
* departments: https://classes.engineering.wustl.edu/cse330/content/departments_data.txt&lt;br /&gt;
* grades: https://classes.engineering.wustl.edu/cse330/content/grades_data.txt&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert entries for CSE 330S, CSE 131, and CSE 260M.&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below. &lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 35.5 in CSE 330S&lt;br /&gt;
#*** 0 in CSE 131&lt;br /&gt;
#*** 95 in CSE 260M&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100 in CSE 330S&lt;br /&gt;
#*** 90.5 in CSE 131&lt;br /&gt;
#*** 94.8 in CSE 260M&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 75 in CSE 330S&lt;br /&gt;
#*** 37 in CSE 131&lt;br /&gt;
#*** 45.5 in CSE 260M&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please Running the following &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; queries, then copy the output to a text file of the form &amp;lt;code&amp;gt;query1.txt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;query2.txt&amp;lt;/code&amp;gt;, and so on, and commit them with the rest of your repository (be sure to include your query command and the entire response, including the number of results found). For each query, only the requested columns should be present. You will receive 0 points for any query that includes additional columns.&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the College of Arts &amp;amp; Sciences (school code &amp;lt;code&amp;gt;L&amp;lt;/code&amp;gt;).&lt;br /&gt;
# The names, student IDs, and CSE330 grades of all students who are in CSE330S.&lt;br /&gt;
#: '''Note:''' This query should involve joins.  You don't need to use any aggregation functions.&lt;br /&gt;
# The names, e-mails, and average grades of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the &amp;lt;code&amp;gt;HAVING&amp;lt;/code&amp;gt; keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of only his student ID, e-mail address, and average grade.&lt;br /&gt;
#: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
#: '''Note:''' Your query must look for students with the name &amp;quot;Jack Johnson&amp;quot; instead of hard-coding the student ID.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your Git repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
* https://news.ycombinator.com/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit story commentary.&lt;br /&gt;
*: A link can be associated with each story, and they should be stored in a separate database field from the story&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit and delete their stories and comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and links).&lt;br /&gt;
* Creative Portion&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
No application is finished until much thought is put into web security and best practice.  Throughout this course, we heavily emphasize the dogma of [https://mirrors.meiert.org/coderesponsibly.org/ responsible] coding.&lt;br /&gt;
&lt;br /&gt;
Read this week's Web Application Security guide: [[Web Application Security, Part 2]].  In particular, your project needs to:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure against SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''Your passwords need to be securely hashed salted''' to prevent rainbow table attacks.&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''You should check all preconditions on the server side''' to prevent Abuse of Functionality attacks.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''Your page should validate''' with no errors or warnings through the W3C validator.&lt;br /&gt;
* '''Filter Input and Escape Output''', but not the other way around.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 100 points total.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0. ''' &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''If you do not include a link to your group portion running on your instance in your group portion README.md, you will receive a 0 for the group portion.''' &lt;br /&gt;
________&lt;br /&gt;
&lt;br /&gt;
# '''MySQL Queries (25 Points):'''&lt;br /&gt;
#* A MySQL server is running on your instance. Put a screenshot in your repository of your terminal connected to your MySQL server. ( (2 points)&lt;br /&gt;
#* Tables' fields, including data types and foreign keys, are correct (8 points)&lt;br /&gt;
#*: ''Note: To demonstrate the structure of your tables, you should commit a text file containing the output of the &amp;lt;code&amp;gt;SHOW CREATE TABLE&amp;lt;/code&amp;gt; command '''for each table.''' Each table's file should have a name of the form &amp;lt;code&amp;gt;tablename.sql&amp;lt;/code&amp;gt; (e.g. &amp;lt;code&amp;gt;students.sql&amp;lt;/code&amp;gt;).''&lt;br /&gt;
#* The output of each of the five queries is correct. (3 points each)&lt;br /&gt;
#*: ''Note: To demonstrate the output of your queries, text files containing the 'entire' result (including the query and number of records found) of running each query should committed to Github. The file for query 1 should be named &amp;lt;code&amp;gt;query1.txt&amp;lt;/code&amp;gt;, the file for query 2 should be named &amp;lt;code&amp;gt;query2.txt&amp;lt;/code&amp;gt;, and so on.''&lt;br /&gt;
# '''News Site (60 Points):'''&lt;br /&gt;
#* '''''User Management (20 Points):'''''&lt;br /&gt;
#** A session is created when a user logs in (3 points)&lt;br /&gt;
#** New users can register (3 points)&lt;br /&gt;
#** Passwords are hashed, salted, and checked securely (3 points)&lt;br /&gt;
#**: ''Note: You will receive 0 points for this section if you use the &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;===&amp;lt;/code&amp;gt; operators to compare password hashes, or if you use the &amp;lt;code&amp;gt;crypt&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;md5&amp;lt;/code&amp;gt; functions at any point.''&lt;br /&gt;
#** Users can log out (3 points)&lt;br /&gt;
#** A user can edit and delete his/her own stories and comments but cannot edit or delete the stories or comments of another user (8 points)&lt;br /&gt;
#* '''''Story and Comment Management (20 Points):'''''&lt;br /&gt;
#** Relational database is configured with correct data types and foreign keys (4 points)&lt;br /&gt;
#*: ''Note: To demonstrate the structure of your database, you should commit a 'single' text file containing the output of the &amp;lt;code&amp;gt;SHOW CREATE TABLE&amp;lt;/code&amp;gt; command '''for all tables in your database,''' called &amp;lt;code&amp;gt;tables.sql&amp;lt;/code&amp;gt;. This one file should contain the output for all of your tables.&lt;br /&gt;
#** Stories can be posted (3 points)&lt;br /&gt;
#** A link can be associated with each story, and is stored in a separate database field from the story (3 points)&lt;br /&gt;
#** Comments can be posted in association with a story (4 points)&lt;br /&gt;
#** Stories can be edited and deleted (3 points)&lt;br /&gt;
#** Comments can be edited and deleted (3 points)&lt;br /&gt;
#**: ''Note: Although there are only 6 points allocated for editing/deleting in this section, there are 8 more points at stake in the User Management section that cannot be earned unless editing/deleting is implemented.  Implementing editing but not deleting, or vice-versa, will result in earning half the points.''&lt;br /&gt;
#* '''''Best Practices (15 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (3 points)&lt;br /&gt;
#** Safe from SQL Injection attacks (2 points)&lt;br /&gt;
#** Site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C HTML and CSS validators (2 points)&lt;br /&gt;
#** CSRF tokens are passed when creating, editing, and deleting comments and stories (5 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** Names and Student IDs of all the group members&lt;br /&gt;
#** A link to your homepage of the site&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2785</id>
		<title>Module 2</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2785"/>
		<updated>2021-02-01T22:58:05Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Creative Portion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
Module 2 introduces you to Linux, a command-line environment, the Apache web server, and PHP.  You will create and configure your own cloud instance, install Apache and related software, and then form groups to make a simple file sharing site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;'''DO NOT WAIT UNTIL THE LAST MINUTE TO START ON THIS (or any) MODULE!'''  The most common reason students perform poorly in this class is procrastination.  You have been warned.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Linux]]&lt;br /&gt;
* [[Bash]]&lt;br /&gt;
* [[Amazon Web Services]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Workflow]]&lt;br /&gt;
* [[VS Code]]&lt;br /&gt;
* [[Web Application Security, Part 1]]&lt;br /&gt;
* [[FAQ - Mod 2]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are a lot of wiki pages that you need to read in order to complete the individual portion of Module 2.  The wiki pages contain an assortment of required steps, optional steps, and information.  To make things easier, we have highlighted the ''required steps'' with a red bar, like you see on the left of this message.  Do not skip anything marked with a red bar, or else you will not have a perfectly configured instance.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Learn About Linux ===&lt;br /&gt;
&lt;br /&gt;
Linux is an open-source operating system based on UNIX. Linux is highly versatile and is used in a wide range of applications.&lt;br /&gt;
&lt;br /&gt;
If you are not a Linux guru, read the Linux guide to get started: [[Linux]]&lt;br /&gt;
&lt;br /&gt;
=== Windows Users Only: Enable Windows Subsystem for Linux (WSL) or Install Cygwin ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need WSL or Cygwin in order to log into and configure your EC2 instance. Cygwin is already installed on the CEC machines. If you're using Windows 10, you can use WSL, which is an officially-supported way of accessing a Linux terminal on Windows. If not, you'll have to use Cygwin. Instructions for installing either on your personal machine are located in [[Workflow#Cygwin|the Workflow guide]].&lt;br /&gt;
&lt;br /&gt;
Mac OS X users should located the &amp;quot;Terminal&amp;quot; application, which is installed by default; you will need this in the coming steps.&lt;br /&gt;
&lt;br /&gt;
=== Create an AWS EC2 Instance ===&lt;br /&gt;
&lt;br /&gt;
Once you understand [[Linux]], you need to set up your Amazon EC2 Instance.  Use the AWS article to guide you through the process: [[Amazon Web Services]]&lt;br /&gt;
&lt;br /&gt;
=== Configure SSH ===&lt;br /&gt;
&lt;br /&gt;
Follow the instructions in [[SSH#SSH Configuration|the SSH guide]] to do the following:&lt;br /&gt;
&lt;br /&gt;
# Create your own SSH key pair&lt;br /&gt;
# Log in as the default user to your EC2 instance&lt;br /&gt;
# Create a new user&lt;br /&gt;
# Give the new user your SSH public key&lt;br /&gt;
&lt;br /&gt;
From now on, when you need to log into your EC2 instance as an administrator, just pop up a terminal and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ssh your-username@ec2-xx-xx-xx-xx.compute-1.amazonaws.com&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To save from typing this command in every time you want to access your server, you can set an '''alias''' in your terminal.&lt;br /&gt;
&lt;br /&gt;
In the '''Mac''' terminal, vim ~/.bash_profile and input the following command:&lt;br /&gt;
 $ alias aws='ssh your-username@ec2.xx-xx-xx-xx.compute-1.amazonaws.com'&lt;br /&gt;
Now, whenever you type aws in your terminal, it will type your ssh command.&lt;br /&gt;
&lt;br /&gt;
In '''Cygwin''', vim ~/.bash_profile and input the following:&lt;br /&gt;
 export aws=&amp;quot;ssh your-username@ec2.xx-xx-xx-xx.compute-1.amazonaws.com&amp;quot;&lt;br /&gt;
And you run this command by typing '''$aws'''&lt;br /&gt;
Also note that you may have to restart your terminal for this to take effect, or put the command in your ~/.bashrc file&lt;br /&gt;
&lt;br /&gt;
=== Install Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
Recall that software installation in Linux instances is usually handled through a package manager, like '''yum'''.  For more information, refer to [[Linux#Repository-Based Package Managers|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working properly, '''install your first package(s) according to the ''Essential Packages'' subsection in the Linux guide.'''&lt;br /&gt;
&lt;br /&gt;
=== Set the Timezone ===&lt;br /&gt;
&lt;br /&gt;
'''Set your server to use US Central time (America/Chicago).'''  Instructions are in the Linux guide: [[Linux#Synchronizing Date and Time]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up the Apache Web Server ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install the Apache web server on your EC2 instance'''.  Refer to [[Apache|the Apache guide]].&lt;br /&gt;
&lt;br /&gt;
In order for your web server to be accessible, you need to '''open up Port 80 on your EC2 instance'''.  Instructions are in the AWS guide: [[Amazon Web Services#Enabling Web Access to your EC2 Instance]]&lt;br /&gt;
&lt;br /&gt;
'''Enable the UserDir module in Apache.'''  Instructions are in the Apache guide: [[Apache#The UserDir Module]]&lt;br /&gt;
&lt;br /&gt;
=== Install PHP ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install PHP on your EC2 server'''.  Instructions are at the top of the PHP guide: [[PHP]]&lt;br /&gt;
&lt;br /&gt;
You need to '''configure PHP to show errors'''.  Instructions are immediately below installation in the PHP guide.&lt;br /&gt;
&lt;br /&gt;
=== Learn about the PHP Language ===&lt;br /&gt;
&lt;br /&gt;
Before you can continue, you will need to make yourself acquainted with PHP language components.  Read the PHP guide for an overview: [[PHP#PHP Language Components]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up your Workspace ===&lt;br /&gt;
&lt;br /&gt;
You are now ready to set up the workspace that you will be using for the rest of the semester.  Follow the instructions in [[Workflow]] to:&lt;br /&gt;
&lt;br /&gt;
# Make an account on GitHub&lt;br /&gt;
# Setup a repo using GitHub Classroom&lt;br /&gt;
# Clone your CSE 330 repo from GitHub&lt;br /&gt;
# Install a text editor such as '''VSCode''' to write your assignments with&lt;br /&gt;
# Either install an FTP client, or use SFTP through command line, to transfer files from your local machine to your instance&lt;br /&gt;
&lt;br /&gt;
=== Calculator ===&lt;br /&gt;
&lt;br /&gt;
'''Make a calculator using PHP and an HTML form.'''  The form should have two inputs.  The form should submit a GET request either back to the same page or to a different results page.  The calculator should support addition, subtraction, multiplication, and division by means of a radio button group on the page.  (Consider edge cases!)&lt;br /&gt;
&lt;br /&gt;
=== Git Tutorial ===&lt;br /&gt;
Complete  [https://github.com/UnseenWizzard/git_training/ this Git tutorial]. After you finish the tutorial, place the git_training folder in your Module 2 Individual repo.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs (that means you and one other person) on this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;In this module, and all future modules, the group portion builds off of material you learn in the individual portion.  You should therefore complete the individual portions prior to working on the group portions.  (Trust us: it will make your life easier!)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple File Sharing Site ===&lt;br /&gt;
&lt;br /&gt;
You will be making a simple file sharing site that supports uploading, viewing, and deleting files associated with various users.  Details:&lt;br /&gt;
&lt;br /&gt;
* You should have a file named '''users.txt''' stored in a secure place on your filesystem.  It should have at least three usernames, with one username per line.&lt;br /&gt;
*: Passwords add an extra layer of complexity (encryption) that we will cover in Module 3.  You will not earn credit for implementing passwords as your creative portion for this module.&lt;br /&gt;
* Users of the file sharing site should be able to enter their username and then log in.&lt;br /&gt;
*: You may implement logins using session variables, or you may implement them using a GET parameter that is passed between pages.  You will need to always use sessions starting in Module 3.&lt;br /&gt;
* Users should see a list of all files associated with their username after the log in.&lt;br /&gt;
* Users should be able to view, upload, and delete files associated with their username.&lt;br /&gt;
* The URI should NOT reveal the internal file structure of your web site.&lt;br /&gt;
** Example of what not to do:  http://www.example.com/download.php?file=/home/paul/file.txt&lt;br /&gt;
** Another bad example:  http://www.example.com/~user/file.txt&lt;br /&gt;
** Good example: http://www.example.com/view.php?user=music&amp;amp;name=file.txt&lt;br /&gt;
*: In general, don't reveal any internal information about the site.&lt;br /&gt;
*: '''Food for thought:''' Given that Apache processes (with the exception of the main process) do not run as root, but rather as the user apache, how can you allow both your user account and the php scripts to read and write the &lt;br /&gt;
*:necessary files?&lt;br /&gt;
*:: ''Hint:'' You shouldn't be storing the user-uploaded files in public_html (that is only the place for your own web-page files), &lt;br /&gt;
*::''Hint number 2:''  you will need to use chown to change permissions to let user apache have permissions on the user-files (that '''are not''' in the public_html folder). If you don't know what this does or how to do this, look at the [[Apache]] page&lt;br /&gt;
* You should customize your file sharing site by implementing an additional feature or two as part of the '''creative portion'''.&lt;br /&gt;
&lt;br /&gt;
You will probably find the PHP guide on this wiki to be helpful: [[PHP#Other PHP Tips]]&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to follow the conventions of FIEO (Filter Input and Escape Output)'''.  Things you should filter include file names, usernames, and so on.&lt;br /&gt;
* '''Your project must pass the W3C Validator with no errors or warnings'''.  For more information, see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 120 points total. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to GitHub by the end of class on the due date. Commit early and often. Failing to commit by the end of class on the due date will result in a 0. &lt;br /&gt;
&lt;br /&gt;
_____________&lt;br /&gt;
&lt;br /&gt;
# '''Cloud Instance and Web Server (30 Points):'''&lt;br /&gt;
#* You can SSH into your instance using your own custom username and SSH key. Put a screenshot in your repository of your terminal SSH-ing into your instance (15 points)&lt;br /&gt;
#* Your custom username is able to perform SUDO commands. Put a screenshot in your repository of you successfully executing a command with sudo (5 points)&lt;br /&gt;
#* The time zone is correct on your instance. Put a screenshot in your repository of the results of the `date` command (5 points)&lt;br /&gt;
#* The UserDir Apache module is working. Place a file in /home/&amp;lt;username&amp;gt;/public_html and link to the file in your README.md (5 points)&lt;br /&gt;
# '''PHP Calculator (15 Points):'''&lt;br /&gt;
#* The calculator is able to perform all four functions with floating point numbers (2 points each, 8 points in total)&lt;br /&gt;
#* Each function is given as a radio button choice (4 points)&lt;br /&gt;
#* The calculator page passes the W3C HTML validator (3 points)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your individual repo with the link to your calculator on your instance.''''' See the Creative Portion section for more information about .md files.&lt;br /&gt;
# '''Git Tutorial (20 Points):'''&lt;br /&gt;
#* Place the git_training folder containing the completed tutorial in your individual assignment repository.&lt;br /&gt;
# '''File Sharing Site (40 Points):'''&lt;br /&gt;
#* '''''File Management (25 Points):'''''&lt;br /&gt;
#** Users should not be able to see any files until they enter a username and log in (4 points)&lt;br /&gt;
#**: ''Remember that users.txt should be stored in a secure location on your filesystem.  That is, '''you should not be able to type any URL into your browser and see the raw users.txt file!'''''&lt;br /&gt;
#** Users can see a list of all files they have uploaded (4 points)&lt;br /&gt;
#** Users can open files they have previously uploaded (5 points)&lt;br /&gt;
#**: ''Note: Users should be able to open not only plain text files but also other file formats: images, spreadsheets, etc.''&lt;br /&gt;
#** Users can upload files (4 points)&lt;br /&gt;
#**: ''Note: Like users.txt, uploaded files should be stored in a secure location on your filesystem.  That is, '''do not keep your uploads directory underneath a directory served by Apache!'''''&lt;br /&gt;
#** Users can delete files.  If a file is &amp;quot;deleted&amp;quot;, it should actually be removed from the filesystem (4 points)&lt;br /&gt;
#** The directory structure is hidden. Users should not be able to access or view files by manipulating a URL. (2 points)&lt;br /&gt;
#** Users can log out (2 points)&lt;br /&gt;
#**: ''Note: If using session variables, you must ''actually'' log out the user by destroying their session; i.e., don't just redirect them to the login screen.''&lt;br /&gt;
#* '''''Best Practices (10 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (4 points)&lt;br /&gt;
#** The site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C validator (3 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** An .md file is a plain text file called a markdown file  [https://guides.github.com/features/mastering-markdown/ ] .  &lt;br /&gt;
#***The contents of your README.md file are shown on your repo, making it easier for us to grade&lt;br /&gt;
#*** You may style the page with bolding, hyperlings, images, block quotes and lists&lt;br /&gt;
#*** [http://dillinger.io/ This online markdown editor] makes it easy to learn this format  &lt;br /&gt;
#** The link to your file sharing site. '''''We need this to grade your work.'''''&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
=== Creative Portion ===&lt;br /&gt;
&lt;br /&gt;
This module and all future modules will require that you invest some time into creating additional features for your group project.  Plan to invest at the very least 60 minutes of your time into the creative portion.  In the above rubric, viewing files is worth five and uploading is worth four. The creative portion is worth fifteen points; it should be a very sizable part of your project.&lt;br /&gt;
&lt;br /&gt;
* The creative portion is an opportunity for you to learn the material of your own interest.&lt;br /&gt;
* You will not earn credit for a creative-portion feature that simply rehashes something you've already done in a previous module.&lt;br /&gt;
&lt;br /&gt;
If you need ideas for a creative portion, or if you want to know whether or not your creative portion idea is &amp;quot;hard enough&amp;quot;, ask a TA.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2784</id>
		<title>Module 2</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2784"/>
		<updated>2021-01-28T03:21:06Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: Changed rubric to reflect new/old git tutorial, small wording/typo fixes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
Module 2 introduces you to Linux, a command-line environment, the Apache web server, and PHP.  You will create and configure your own cloud instance, install Apache and related software, and then form groups to make a simple file sharing site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;'''DO NOT WAIT UNTIL THE LAST MINUTE TO START ON THIS (or any) MODULE!'''  The most common reason students perform poorly in this class is procrastination.  You have been warned.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Linux]]&lt;br /&gt;
* [[Bash]]&lt;br /&gt;
* [[Amazon Web Services]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Workflow]]&lt;br /&gt;
* [[VS Code]]&lt;br /&gt;
* [[Web Application Security, Part 1]]&lt;br /&gt;
* [[FAQ - Mod 2]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are a lot of wiki pages that you need to read in order to complete the individual portion of Module 2.  The wiki pages contain an assortment of required steps, optional steps, and information.  To make things easier, we have highlighted the ''required steps'' with a red bar, like you see on the left of this message.  Do not skip anything marked with a red bar, or else you will not have a perfectly configured instance.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Learn About Linux ===&lt;br /&gt;
&lt;br /&gt;
Linux is an open-source operating system based on UNIX. Linux is highly versatile and is used in a wide range of applications.&lt;br /&gt;
&lt;br /&gt;
If you are not a Linux guru, read the Linux guide to get started: [[Linux]]&lt;br /&gt;
&lt;br /&gt;
=== Windows Users Only: Enable Windows Subsystem for Linux (WSL) or Install Cygwin ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need WSL or Cygwin in order to log into and configure your EC2 instance. Cygwin is already installed on the CEC machines. If you're using Windows 10, you can use WSL, which is an officially-supported way of accessing a Linux terminal on Windows. If not, you'll have to use Cygwin. Instructions for installing either on your personal machine are located in [[Workflow#Cygwin|the Workflow guide]].&lt;br /&gt;
&lt;br /&gt;
Mac OS X users should located the &amp;quot;Terminal&amp;quot; application, which is installed by default; you will need this in the coming steps.&lt;br /&gt;
&lt;br /&gt;
=== Create an AWS EC2 Instance ===&lt;br /&gt;
&lt;br /&gt;
Once you understand [[Linux]], you need to set up your Amazon EC2 Instance.  Use the AWS article to guide you through the process: [[Amazon Web Services]]&lt;br /&gt;
&lt;br /&gt;
=== Configure SSH ===&lt;br /&gt;
&lt;br /&gt;
Follow the instructions in [[SSH#SSH Configuration|the SSH guide]] to do the following:&lt;br /&gt;
&lt;br /&gt;
# Create your own SSH key pair&lt;br /&gt;
# Log in as the default user to your EC2 instance&lt;br /&gt;
# Create a new user&lt;br /&gt;
# Give the new user your SSH public key&lt;br /&gt;
&lt;br /&gt;
From now on, when you need to log into your EC2 instance as an administrator, just pop up a terminal and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ssh your-username@ec2-xx-xx-xx-xx.compute-1.amazonaws.com&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To save from typing this command in every time you want to access your server, you can set an '''alias''' in your terminal.&lt;br /&gt;
&lt;br /&gt;
In the '''Mac''' terminal, vim ~/.bash_profile and input the following command:&lt;br /&gt;
 $ alias aws='ssh your-username@ec2.xx-xx-xx-xx.compute-1.amazonaws.com'&lt;br /&gt;
Now, whenever you type aws in your terminal, it will type your ssh command.&lt;br /&gt;
&lt;br /&gt;
In '''Cygwin''', vim ~/.bash_profile and input the following:&lt;br /&gt;
 export aws=&amp;quot;ssh your-username@ec2.xx-xx-xx-xx.compute-1.amazonaws.com&amp;quot;&lt;br /&gt;
And you run this command by typing '''$aws'''&lt;br /&gt;
Also note that you may have to restart your terminal for this to take effect, or put the command in your ~/.bashrc file&lt;br /&gt;
&lt;br /&gt;
=== Install Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
Recall that software installation in Linux instances is usually handled through a package manager, like '''yum'''.  For more information, refer to [[Linux#Repository-Based Package Managers|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working properly, '''install your first package(s) according to the ''Essential Packages'' subsection in the Linux guide.'''&lt;br /&gt;
&lt;br /&gt;
=== Set the Timezone ===&lt;br /&gt;
&lt;br /&gt;
'''Set your server to use US Central time (America/Chicago).'''  Instructions are in the Linux guide: [[Linux#Synchronizing Date and Time]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up the Apache Web Server ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install the Apache web server on your EC2 instance'''.  Refer to [[Apache|the Apache guide]].&lt;br /&gt;
&lt;br /&gt;
In order for your web server to be accessible, you need to '''open up Port 80 on your EC2 instance'''.  Instructions are in the AWS guide: [[Amazon Web Services#Enabling Web Access to your EC2 Instance]]&lt;br /&gt;
&lt;br /&gt;
'''Enable the UserDir module in Apache.'''  Instructions are in the Apache guide: [[Apache#The UserDir Module]]&lt;br /&gt;
&lt;br /&gt;
=== Install PHP ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install PHP on your EC2 server'''.  Instructions are at the top of the PHP guide: [[PHP]]&lt;br /&gt;
&lt;br /&gt;
You need to '''configure PHP to show errors'''.  Instructions are immediately below installation in the PHP guide.&lt;br /&gt;
&lt;br /&gt;
=== Learn about the PHP Language ===&lt;br /&gt;
&lt;br /&gt;
Before you can continue, you will need to make yourself acquainted with PHP language components.  Read the PHP guide for an overview: [[PHP#PHP Language Components]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up your Workspace ===&lt;br /&gt;
&lt;br /&gt;
You are now ready to set up the workspace that you will be using for the rest of the semester.  Follow the instructions in [[Workflow]] to:&lt;br /&gt;
&lt;br /&gt;
# Make an account on GitHub&lt;br /&gt;
# Setup a repo using GitHub Classroom&lt;br /&gt;
# Clone your CSE 330 repo from GitHub&lt;br /&gt;
# Install a text editor such as '''VSCode''' to write your assignments with&lt;br /&gt;
# Either install an FTP client, or use SFTP through command line, to transfer files from your local machine to your instance&lt;br /&gt;
&lt;br /&gt;
=== Calculator ===&lt;br /&gt;
&lt;br /&gt;
'''Make a calculator using PHP and an HTML form.'''  The form should have two inputs.  The form should submit a GET request either back to the same page or to a different results page.  The calculator should support addition, subtraction, multiplication, and division by means of a radio button group on the page.  (Consider edge cases!)&lt;br /&gt;
&lt;br /&gt;
=== Git Tutorial ===&lt;br /&gt;
Complete  [https://github.com/UnseenWizzard/git_training/ this Git tutorial]. After you finish the tutorial, place the git_training folder in your Module 2 Individual repo.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs (that means you and one other person) on this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;In this module, and all future modules, the group portion builds off of material you learn in the individual portion.  You should therefore complete the individual portions prior to working on the group portions.  (Trust us: it will make your life easier!)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple File Sharing Site ===&lt;br /&gt;
&lt;br /&gt;
You will be making a simple file sharing site that supports uploading, viewing, and deleting files associated with various users.  Details:&lt;br /&gt;
&lt;br /&gt;
* You should have a file named '''users.txt''' stored in a secure place on your filesystem.  It should have at least three usernames, with one username per line.&lt;br /&gt;
*: Passwords add an extra layer of complexity (encryption) that we will cover in Module 3.  You will not earn credit for implementing passwords as your creative portion for this module.&lt;br /&gt;
* Users of the file sharing site should be able to enter their username and then log in.&lt;br /&gt;
*: You may implement logins using session variables, or you may implement them using a GET parameter that is passed between pages.  You will need to always use sessions starting in Module 3.&lt;br /&gt;
* Users should see a list of all files associated with their username after the log in.&lt;br /&gt;
* Users should be able to view, upload, and delete files associated with their username.&lt;br /&gt;
* The URI should NOT reveal the internal file structure of your web site.&lt;br /&gt;
** Example of what not to do:  http://www.example.com/download.php?file=/home/paul/file.txt&lt;br /&gt;
** Another bad example:  http://www.example.com/~user/file.txt&lt;br /&gt;
** Good example: http://www.example.com/view.php?user=music&amp;amp;name=file.txt&lt;br /&gt;
*: In general, don't reveal any internal information about the site.&lt;br /&gt;
*: '''Food for thought:''' Given that Apache processes (with the exception of the main process) do not run as root, but rather as the user apache, how can you allow both your user account and the php scripts to read and write the &lt;br /&gt;
*:necessary files?&lt;br /&gt;
*:: ''Hint:'' You shouldn't be storing the user-uploaded files in public_html (that is only the place for your own web-page files), &lt;br /&gt;
*::''Hint number 2:''  you will need to use chown to change permissions to let user apache have permissions on the user-files (that '''are not''' in the public_html folder). If you don't know what this does or how to do this, look at the [[Apache]] page&lt;br /&gt;
* You should customize your file sharing site by implementing an additional feature or two as part of the '''creative portion'''.&lt;br /&gt;
&lt;br /&gt;
You will probably find the PHP guide on this wiki to be helpful: [[PHP#Other PHP Tips]]&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to follow the conventions of FIEO (Filter Input and Escape Output)'''.  Things you should filter include file names, usernames, and so on.&lt;br /&gt;
* '''Your project must pass the W3C Validator with no errors or warnings'''.  For more information, see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 120 points total. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to GitHub by the end of class on the due date. Commit early and often. Failing to commit by the end of class on the due date will result in a 0. &lt;br /&gt;
&lt;br /&gt;
_____________&lt;br /&gt;
&lt;br /&gt;
# '''Cloud Instance and Web Server (30 Points):'''&lt;br /&gt;
#* You can SSH into your instance using your own custom username and SSH key. Put a screenshot in your repository of your terminal SSH-ing into your instance (15 points)&lt;br /&gt;
#* Your custom username is able to perform SUDO commands. Put a screenshot in your repository of you successfully executing a command with sudo (5 points)&lt;br /&gt;
#* The time zone is correct on your instance. Put a screenshot in your repository of the results of the `date` command (5 points)&lt;br /&gt;
#* The UserDir Apache module is working. Place a file in /home/&amp;lt;username&amp;gt;/public_html and link to the file in your README.md (5 points)&lt;br /&gt;
# '''PHP Calculator (15 Points):'''&lt;br /&gt;
#* The calculator is able to perform all four functions with floating point numbers (2 points each, 8 points in total)&lt;br /&gt;
#* Each function is given as a radio button choice (4 points)&lt;br /&gt;
#* The calculator page passes the W3C HTML validator (3 points)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your individual repo with the link to your calculator on your instance.''''' See the Creative Portion section for more information about .md files.&lt;br /&gt;
# '''Git Tutorial (20 Points):'''&lt;br /&gt;
#* Place the git_training folder containing the completed tutorial in your individual assignment repository.&lt;br /&gt;
# '''File Sharing Site (40 Points):'''&lt;br /&gt;
#* '''''File Management (25 Points):'''''&lt;br /&gt;
#** Users should not be able to see any files until they enter a username and log in (4 points)&lt;br /&gt;
#**: ''Remember that users.txt should be stored in a secure location on your filesystem.  That is, '''you should not be able to type any URL into your browser and see the raw users.txt file!'''''&lt;br /&gt;
#** Users can see a list of all files they have uploaded (4 points)&lt;br /&gt;
#** Users can open files they have previously uploaded (5 points)&lt;br /&gt;
#**: ''Note: Users should be able to open not only plain text files but also other file formats: images, spreadsheets, etc.''&lt;br /&gt;
#** Users can upload files (4 points)&lt;br /&gt;
#**: ''Note: Like users.txt, uploaded files should be stored in a secure location on your filesystem.  That is, '''do not keep your uploads directory underneath a directory served by Apache!'''''&lt;br /&gt;
#** Users can delete files.  If a file is &amp;quot;deleted&amp;quot;, it should actually be removed from the filesystem (4 points)&lt;br /&gt;
#** The directory structure is hidden. Users should not be able to access or view files by manipulating a URL. (2 points)&lt;br /&gt;
#** Users can log out (2 points)&lt;br /&gt;
#**: ''Note: If using session variables, you must ''actually'' log out the user by destroying their session; i.e., don't just redirect them to the login screen.''&lt;br /&gt;
#* '''''Best Practices (10 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (4 points)&lt;br /&gt;
#** The site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C validator (3 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** An .md file is a plain text file called a markdown file  [https://guides.github.com/features/mastering-markdown/ ] .  &lt;br /&gt;
#***The contents of your README.md file are shown on your repo, making it easier for us to grade&lt;br /&gt;
#*** You may style the page with bolding, hyperlings, images, block quotes and lists&lt;br /&gt;
#*** [http://dillinger.io/ This online markdown editor] makes it easy to learn this format  &lt;br /&gt;
#** The link to your file sharing site. '''''We need this to grade your work.'''''&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
=== Creative Portion ===&lt;br /&gt;
&lt;br /&gt;
This module and all future modules will require that you invest some time into creating additional features for your group project.  Plan to invest at least 60 minutes of your time into the creative portion.&lt;br /&gt;
&lt;br /&gt;
* The creative portion is an opportunity for you to learn the material of your own interest.&lt;br /&gt;
* You will not earn credit for a creative-portion feature that simply rehashes something you've already done in a previous module.&lt;br /&gt;
&lt;br /&gt;
If you need ideas for a creative portion, or if you want to know whether or not your creative portion idea is &amp;quot;hard enough&amp;quot;, ask a TA.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Introduction_to_MySQL&amp;diff=2783</id>
		<title>Introduction to MySQL</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Introduction_to_MySQL&amp;diff=2783"/>
		<updated>2021-01-28T03:09:45Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* phpMyAdmin */ Updated page with new version of phpMyAdmin for Linux 2 AMI&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article is an introduction to MySQL, a database used in conjunction with web applications.&lt;br /&gt;
&lt;br /&gt;
== Why Use a Database? ==&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a web site that used flatfiles to keep track of usernames and uploaded file associations.  However, flatfiles are insecure, lack complex logic, and are impractical for a large-scale web application.  This is where databases come in.  Databases are designed from the ground up to be fast, efficient, and powerful storage solutions for any amount of data.&lt;br /&gt;
&lt;br /&gt;
In CSE330, we will be using '''MySQL''', which is a popular, open-source ''relational database management system'' for web applications.&lt;br /&gt;
&lt;br /&gt;
== Database Structure ==&lt;br /&gt;
&lt;br /&gt;
A MySQL server consists of ''databases'', each of which contains ''tables''.  Tables, in turn, consist of one or more ''fields'' (like columns), and the data is stored in one or more ''entries'' (like rows).  A field in a table can be designated as an ''index''; that is, something that can be used to look up the information in the database.  The set of tables, fields, and indices in your database is called your ''schema''.&lt;br /&gt;
&lt;br /&gt;
MySQL uses the '''Structured Query Language (SQL)''' for manipulating data.&lt;br /&gt;
&lt;br /&gt;
=== Storage Engines ===&lt;br /&gt;
&lt;br /&gt;
MySQL is a database server, but under the hood, it actually uses a '''storage engine''' to retrieve the data.  Two storage engines that are popular in the MySQL community are '''InnoDB''' and '''MyISAM'''.  MyISAM is slightly faster than InnoDB, and it specializes in database schemas that involve predominantly ''SELECT'' and ''INSERT'' queries (which you will learn about later).  However, MyISAM lacks InnoDB's power in making relations between tables, and MyISAM also does not support InnoDB's database transactions.  [http://www.akadia.com/services/mysql_survival.html Click here for more information regarding the differences between MyISAM and InnoDB.]&lt;br /&gt;
&lt;br /&gt;
In CSE330, we will be using InnoDB for our primary MySQL storage engine because of its support for foreign key constraints.  However, in your personal applications down the road, feel free to use either InnoDB or MyISAM.&lt;br /&gt;
&lt;br /&gt;
== Installing and Configuring MySQL ==&lt;br /&gt;
&lt;br /&gt;
To use MySQL, you need the MySQL Server package.  Because we will be interacting with MySQL primarily from PHP scripts, we will also need the associated PHP libraries. In '''yum (RHEL)''', you need the packages '''mariadb-server''' and '''php-mbstring''', and from '''amazon-linux-extras''', you need the package '''lamp-mariadb10.2-php7.2'''. If you're wondering what MariaDB is, it is a fork of MySQL server that is recommended by Amazon for use with Linux 2 AMI systems. For our purposes, MariaDB and MySQL are effectively identical.&lt;br /&gt;
&lt;br /&gt;
To install these packages from their respective package repositories, run the following two commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum install -y mariadb-server php-mbstring&lt;br /&gt;
$ sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to restart Apache after installing any packages relating to your web server!&lt;br /&gt;
&lt;br /&gt;
Run these commands to start the server and the client automatically on startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo systemctl start mariadb&lt;br /&gt;
$ sudo systemctl enable mariadb&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the following command to set the MySQL root user password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mysqladmin -u root password&lt;br /&gt;
New password: &lt;br /&gt;
Confirm new password: &lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When it asks, type the new password, press Enter, and then type the new password again.  You cannot see what you are typing because a password is supposed to be secret.  If the shell displayed the password to you while you were typing it, it would be forever saved in ''~/.bash_history''!&lt;br /&gt;
&lt;br /&gt;
== Using MySQL from the Command Line ==&lt;br /&gt;
&lt;br /&gt;
To interface with MySQL/MariaDB from the command line, use the &amp;lt;code&amp;gt;mysql&amp;lt;/code&amp;gt; command.  The syntax is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mysql -u USERNAME -p DATABASENAME&lt;br /&gt;
Welcome to the MariaDB monitor. ...&lt;br /&gt;
&lt;br /&gt;
MariaDB [(DATABASENAME)]&amp;gt; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''-u''' argument specifies a specific user to use MySQL/MariaDB with, and the '''-p''' argument specifies that you would like to use a password to login to that user. If you add the '''-p''' argument, you will be prompted for the password associated with USERNAME. Failing to provide the '''-p''' is the same as attempting to log in with no password. '''DATABASENAME''' is optional; if this is your first time using MySQL from the command line, you should probably leave this blank.&lt;br /&gt;
&lt;br /&gt;
== Managing Databases ==&lt;br /&gt;
&lt;br /&gt;
To create a database on your MySQL server, simply run the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create database DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can delete a database using the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
drop database DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you're at the MySQL prompt, use the following query to select a database to which to run select, insert, update, and delete queries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
use DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL User Management ==&lt;br /&gt;
&lt;br /&gt;
The first time you log into MySQL, you will need to use the root user, with the password that you specified earlier.  However, it is unwise to use the root user for everyday operations with your MySQL database.&lt;br /&gt;
&lt;br /&gt;
=== Creating a New User ===&lt;br /&gt;
&lt;br /&gt;
To create a new user named USERNAME with the password PASSWORD, run the following query inside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create user 'USERNAME'@'localhost' identified by 'PASSWORD';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create USERNAME, but that user will not have privileges to access any databases.&lt;br /&gt;
&lt;br /&gt;
=== Granting Privileges ===&lt;br /&gt;
&lt;br /&gt;
MySQL provides the '''grant''' command to grant privileges to a user.  The syntax for assigning USERNAME some PRIVILEGES on a TABLE in a DATABASE is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant PRIVILEGES on DATABASE.TABLE to USERNAME@'localhost';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to grant global privileges to a certain administrative user, run the query like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant all on *.* to USERNAME@'localhost' with grant option;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ''with grant option'' enables this user to create other users and assign them permissions, like we are doing here.&lt;br /&gt;
&lt;br /&gt;
If you want to grant privileges to a certain user so that they can only manipulate data in a certain database (a wise idea for when you create a user to use in your PHP web application), run the query like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant select,insert,update,delete on DATABASE.* to USERNAME@'localhost';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever you change privileges, you also need to run the query &amp;lt;code&amp;gt;flush privileges;&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
flush privileges;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== phpMyAdmin ==&lt;br /&gt;
&lt;br /&gt;
It is often cumbersome to SSH into your server every time you want to interact with your database.  A popular web-based window into your MySQL server is '''phpMyAdmin'''.&lt;br /&gt;
&lt;br /&gt;
=== Installing phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
To add phpMyAdmin to apache's root server, you need to make your user apart of the apache group, and change the owner of the root directory to apache.&lt;br /&gt;
&lt;br /&gt;
To add your user to the apache group:&lt;br /&gt;
 $ sudo usermod -a -G apache YOUR_USERNAME&lt;br /&gt;
'''Note you may have to exit your server and ssh back in for this to take effect'''&lt;br /&gt;
&lt;br /&gt;
Change the owner of the www folders to your user, and the group apache&lt;br /&gt;
 $ sudo chown -R YOUR_USERNAME:apache /var/www&lt;br /&gt;
&lt;br /&gt;
'''Now that you can access the /var/www/html directory''' download phpMyAdmin to apache's root directory using '''wget''', extract it using '''tar -xzvf''', and then remove the archive using '''rm''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd /var/www/html&lt;br /&gt;
$ wget 'https://files.phpmyadmin.net/phpMyAdmin/5.0.4/phpMyAdmin-5.0.4-all-languages.tar.gz'&lt;br /&gt;
&lt;br /&gt;
$ ls&lt;br /&gt;
phpMyAdmin-5.0.4-all-languages.tar.gz&lt;br /&gt;
&lt;br /&gt;
$ mkdir phpmyadmin &amp;amp;&amp;amp; tar -xvzf phpMyAdmin-5.0.4-all-languages.tar.gz -C phpmyadmin --strip-components 1&lt;br /&gt;
&lt;br /&gt;
$ ls&lt;br /&gt;
phpmyadmin  phpMyAdmin-5.0.4-all-languages.tar.gz&lt;br /&gt;
&lt;br /&gt;
$ rm phpMyAdmin-5.0.4-all-languages.tar.gz&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, create a phpMyAdmin configuration file, which needs to be saved as '''config.inc.php'''.  The easiest way to do this is to copy the '''config.sample.inc.php''' file that is included with your download.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd /var/www/html/phpmyadmin&lt;br /&gt;
$ sudo cp config.sample.inc.php config.inc.php&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, open config.inc.php in your favorite text editor (if you forgot how, refer to [[Linux#File Editors|the Linux guide]]), and edit the following line, putting in something random for &amp;quot;mySecretHere&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $cfg['blowfish_secret'] = 'mySecretHere';&lt;br /&gt;
&lt;br /&gt;
Finally, restart Apache, and you're good to go.  phpMyAdmin will be accessible via http://ec2-blah-blah.compute-1.amazonaws.com/phpmyadmin/&lt;br /&gt;
&lt;br /&gt;
===== Troubleshooting =====&lt;br /&gt;
&lt;br /&gt;
Older versions of the phpmyadmin package in apt required that you perform one additional step: let Apache know that phpMyAdmin was installed.  The new version does this automatically so long as you check the &amp;quot;apache&amp;quot; box in the first step of the installation process.&lt;br /&gt;
&lt;br /&gt;
To manually hook up phpMyAdmin with Apache, run the following command to symlink ''phpmyadmin.conf'' into Apache's ''conf.d'' directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf&lt;br /&gt;
$ sudo apache2ctl restart  # restart Apache&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Once phpMyAdmin is installed, you will see a login screen.  Log in using a non-root username and password you set up in the previous section.  Once inside, you will see a GUI for interacting with your MySQL database.&lt;br /&gt;
&lt;br /&gt;
Even with the GUI, it is often easier to run queries manually, especially when doing operations like creating a table.  To run a query manually, click either the &amp;quot;SQL&amp;quot; tab or the little icon in the toolbar on the upper-left-hand side of the screen that looks like a database cluster (it's third from the left).&lt;br /&gt;
&lt;br /&gt;
== MySQL Schema and State ==&lt;br /&gt;
&lt;br /&gt;
Read the [[MySQL Schema and State]] guide for more information.&lt;br /&gt;
&lt;br /&gt;
== Using MySQL in PHP ==&lt;br /&gt;
&lt;br /&gt;
Read the [[PHP and MySQL]] guide for more information.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Apache&amp;diff=2782</id>
		<title>Apache</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Apache&amp;diff=2782"/>
		<updated>2021-01-27T17:12:28Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Installing Apache */  Added instructions to start Apache after installing it&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''Apache'' is the industry standard web server for Linux distributions.  It is highly configurable and has a wide range of modules ready for different needs.&lt;br /&gt;
&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=permanence&lt;br /&gt;
|id=910&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== What is a web server? ==&lt;br /&gt;
&lt;br /&gt;
A web server is software that listens for connections to your machine, and when a connection is receive, processes the request and responds with the appropriate information.  Most web servers listen on port 80, which is reserved for the purpose, and use the HTTP protocol.&lt;br /&gt;
&lt;br /&gt;
For example, when you visit this wiki, you are sending a request over the internet to some machine that is probably located somewhere in EIT (the user seldom knows exactly where the machine is located).  The web server receives your request, and it processes the data you sent.  Finally, the server prepares a response (the web page), and sends it back to you.&lt;br /&gt;
&lt;br /&gt;
== Installing Apache ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
In yum, Apache is distributed under the package name '''httpd''' (for ''hypertext transfer protocol daemon'').  Use the package manager associated with your distribution to install Apache.  (For more information on how to use yum, see [[Linux#Repository-Based Package Managers|the Linux guide]].)&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum update&lt;br /&gt;
$ sudo yum install httpd&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You'll need to run this command to add Apache as a startup item:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo /sbin/chkconfig --levels 235 httpd on&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In RHEL, most Apache configurations are stored in ''/etc/httpd/conf/httpd.conf'' and others are located in the directory ''/etc/httpd/conf.d/''.&lt;br /&gt;
&lt;br /&gt;
At this point, Apache has been installed, but is not yet running. To start the webserver, run this command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo /usr/sbin/apachectl start&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Apache Directives ==&lt;br /&gt;
&lt;br /&gt;
You define your settings for Apache using ''directives''.  Some of the directives you will likely encounter include:&lt;br /&gt;
&lt;br /&gt;
* '''DocumentRoot:''' The path to the directory where the top level web files are going to be stored.&lt;br /&gt;
* '''IfModule:'''  The following block would be included if specified module exists.&lt;br /&gt;
* '''User:''' Which user apache2 will run as.&lt;br /&gt;
* '''Group:''' Which group will have group access to default web files.&lt;br /&gt;
* '''AccessFileName:''' The name of the access file (that specifies user names/passwords and other limitations to files/directories).&lt;br /&gt;
* '''ErrorLog:''' Where any errors will be written.&lt;br /&gt;
* '''Include:''' Include some other files.&lt;br /&gt;
* '''LogFormat:''' How to write a log message.&lt;br /&gt;
* '''ErrorDocument:''' Files to display for some HTTP errors (500, 404, 402 etc.).&lt;br /&gt;
* '''Alias:''' Map a directory URL to some other location on your filesystem.  Requires that the ''Alias'' module be loaded.&lt;br /&gt;
&lt;br /&gt;
=== .htaccess Files ===&lt;br /&gt;
&lt;br /&gt;
You can also specify some Apache configurations without delving into the master configuration file.  To do this, put a file named ''.htaccess'' in any directory that Apache is serving.  All directives in it will be interpreted as if they were in a Directory directive in the master configuration file.&lt;br /&gt;
&lt;br /&gt;
'''VERY IMPORTANT:''' The directory containing ''.htaccess'' must not have the '''AllowOverride None''' directive in the master configuration file in order for '''.htaccess''' to be read.&lt;br /&gt;
=== Directory Directive ===&lt;br /&gt;
&lt;br /&gt;
Use the Directory directive to assign other directives to a specific directory.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Directory /var/www/&amp;gt;&lt;br /&gt;
	Options Indexes FollowSymLinks &lt;br /&gt;
	AllowOverride None&lt;br /&gt;
	Order allow,deny&lt;br /&gt;
	allow from all&lt;br /&gt;
	RedirectMatch ^/$ /apache2-default/&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets options for the ''/var/www'' directory.&lt;br /&gt;
# The '''Options''' directive says that:&lt;br /&gt;
## If no index page is present in a directory, display a directory index page instead&lt;br /&gt;
## Apache will follow symbolic links in the directory&lt;br /&gt;
# '''AllowOverride None''' says that ''.htaccess'' files cannot alter the Apache options in this directory and all sub-directories&lt;br /&gt;
# '''Order allow,deny''' and '''Allow from all''' specifies that anybody is allowed to access this server via HTTP.&lt;br /&gt;
&lt;br /&gt;
Note that this directory is actually the root directory of the web server.&lt;br /&gt;
&lt;br /&gt;
== The UserDir Module ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
The UserDir module lets you access files for any user on the server with a ~, e.g., http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/~paul/&lt;br /&gt;
&lt;br /&gt;
This module comes installed, but not activated by default.&lt;br /&gt;
&lt;br /&gt;
=== Enabling UserDir in RHEL ===&lt;br /&gt;
&lt;br /&gt;
If you are using an RHEL-based distribution for your server (like the Amazon AMI), you need to edit the master Apache configuration file.&lt;br /&gt;
&lt;br /&gt;
Open ''/etc/httpd/conf.d/userdir.conf'' in your favorite text editor.  For more information on command-line text editors, refer to [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
Find the line that says&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir disabled&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and change it to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir disabled root&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, find the line that says&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;#UserDir public_html&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and uncomment it; that is, remove the # so that you have&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir public_html&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells Apache that the directory containing each user's html files is a subdirectory of their home directory called public_html.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Users need to manually create public_html.  It is not created automatically.&lt;br /&gt;
&lt;br /&gt;
You may also need to change the permissions of your user directory and your public_html directory to allow Apache to read and execute inside them.  To do this, run the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo chmod o+x /home/myusername&lt;br /&gt;
$ sudo chmod o+rx /home/myusername/public_html&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, [[#Restarting Apache and Testing|restart Apache]].&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Remapping UserDir ===&lt;br /&gt;
&lt;br /&gt;
If you want to change the name of the UserDir web server root from '''public_html''' to something else like '''.html''', follow these instructions.  (You do not need to do this for the purposes of CSE 330; this serves as a reference.)&lt;br /&gt;
&lt;br /&gt;
# Rename your '''public_html''' to '''.html'''&lt;br /&gt;
#* The &amp;quot;.&amp;quot; in front of the directory name means that the directory is a hidden one.  You will not see it with the normal &amp;quot;ls&amp;quot; command.  Use &amp;quot;ls -a&amp;quot; to see hidden files as well.&lt;br /&gt;
# Edit the UserDir configuration file.&lt;br /&gt;
#* In RHEL, edit the userDir configuration file at ''/etc/httpd/conf.d/userdir.conf''&lt;br /&gt;
# Find the line that reads &amp;lt;code&amp;gt;UserDir public_html&amp;lt;/code&amp;gt; and change it to &amp;lt;code&amp;gt;UserDir .html/&amp;lt;/code&amp;gt;&lt;br /&gt;
# [[#Restarting Apache and Testing|Restart Apache]].&lt;br /&gt;
&lt;br /&gt;
== Apache Logs ==&lt;br /&gt;
&lt;br /&gt;
Apache creates two log files: one for all access attempts to your server, and one for errors.  The locations of these log files are:&lt;br /&gt;
&lt;br /&gt;
* '''Access Log:''' /var/log/httpd/access_log&lt;br /&gt;
* '''Error Log:''' /var/log/httpd/error_log&lt;br /&gt;
&lt;br /&gt;
You might find it helpful to see access and errors appear &amp;quot;live&amp;quot; in your terminal window as they are created.  To do this, you can use the [[Linux#Command Reference|tail -f]] command.  Since the log files have strict permissions, you will need to also use sudo.  Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo tail -f /var/log/httpd/access_log&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Virtual Hosts ==&lt;br /&gt;
&lt;br /&gt;
'''Virtual Hosts''' are used to run multiple Apache web servers from the same machine.  Virtual hosts can listen for connections on different ports and/or different hostnames, serving completely different web sites to each.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost cse330.dyndns.org&amp;gt;&lt;br /&gt;
	ServerAdmin webmaster@localhost&lt;br /&gt;
	ServerName cse330.dyndns.org&lt;br /&gt;
	DocumentRoot /home/www/cse330/&lt;br /&gt;
	ErrorLog /var/log/httpd/error_log&lt;br /&gt;
	LogLevel warn&lt;br /&gt;
	CustomLog /var/log/apache2/access_log combined&lt;br /&gt;
	ServerSignature On&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration enables any requests that use a host name of ''cse330.dyndns.org'' will use ''/home/www/cse330'' as the root document directory.  Make sure that the DocumentRoot directory exists and is readable by the httpd process.  In RHEL, Apache runs as the '''apache''' user.&lt;br /&gt;
&lt;br /&gt;
It is good practice to put raw server configuration files in ''/etc/httpd/sites-available''.  To activate a site, create a symlink from the configuration in ''sites-available'' to a sibling directory called ''sites-enabled''.&lt;br /&gt;
&lt;br /&gt;
== Restarting Apache and Testing ==&lt;br /&gt;
&lt;br /&gt;
Whenever you make changes to the Apache configuration files, you will need to restart Apache for the changes to take effect.  There are several different ways to restart Apache; they all functionally do (almost) the same thing, so choose your favorite:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo /usr/sbin/apachectl restart&lt;br /&gt;
$ sudo apachectl restart    # if /usr/sbin is in your PATH (which it is *not* by default in RHEL)&lt;br /&gt;
$ sudo /etc/init.d/httpd restart&lt;br /&gt;
$ sudo /sbin/service httpd restart&lt;br /&gt;
$ sudo service httpd restart&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're torn for which version is the &amp;quot;best&amp;quot; to use, the commands involving '''apachectl''' (think &amp;quot;Apache Control&amp;quot;) are written by the Apache folks themselves.  This has a couple advantages:&lt;br /&gt;
* They show you errors in the startup process (if there are any)&lt;br /&gt;
* They give you the option to perform a &amp;quot;soft&amp;quot; restart; that is, a restart that allows any pending connections to complete.  To perform a soft restart, use ''graceful'': &amp;lt;code&amp;gt;sudo apachectl graceful&amp;lt;/code&amp;gt;&lt;br /&gt;
In my anecdotal experience, the '''apachectl''' commands are also faster than the '''service''' or '''init.d''' commands.&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working, create a test file in your home directory under public_html, and then point your browser to it: http://ec2-xxx-xx-xx-xxx.compute-1.amazonaws.com/~yourUserName/hello.txt&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Introduction_to_MySQL&amp;diff=2779</id>
		<title>Introduction to MySQL</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Introduction_to_MySQL&amp;diff=2779"/>
		<updated>2021-01-23T22:38:47Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Using MySQL from the Command Line */ Added additional information about parameters, modified example slightly for MariaDB&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article is an introduction to MySQL, a database used in conjunction with web applications.&lt;br /&gt;
&lt;br /&gt;
== Why Use a Database? ==&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a web site that used flatfiles to keep track of usernames and uploaded file associations.  However, flatfiles are insecure, lack complex logic, and are impractical for a large-scale web application.  This is where databases come in.  Databases are designed from the ground up to be fast, efficient, and powerful storage solutions for any amount of data.&lt;br /&gt;
&lt;br /&gt;
In CSE330, we will be using '''MySQL''', which is a popular, open-source ''relational database management system'' for web applications.&lt;br /&gt;
&lt;br /&gt;
== Database Structure ==&lt;br /&gt;
&lt;br /&gt;
A MySQL server consists of ''databases'', each of which contains ''tables''.  Tables, in turn, consist of one or more ''fields'' (like columns), and the data is stored in one or more ''entries'' (like rows).  A field in a table can be designated as an ''index''; that is, something that can be used to look up the information in the database.  The set of tables, fields, and indices in your database is called your ''schema''.&lt;br /&gt;
&lt;br /&gt;
MySQL uses the '''Structured Query Language (SQL)''' for manipulating data.&lt;br /&gt;
&lt;br /&gt;
=== Storage Engines ===&lt;br /&gt;
&lt;br /&gt;
MySQL is a database server, but under the hood, it actually uses a '''storage engine''' to retrieve the data.  Two storage engines that are popular in the MySQL community are '''InnoDB''' and '''MyISAM'''.  MyISAM is slightly faster than InnoDB, and it specializes in database schemas that involve predominantly ''SELECT'' and ''INSERT'' queries (which you will learn about later).  However, MyISAM lacks InnoDB's power in making relations between tables, and MyISAM also does not support InnoDB's database transactions.  [http://www.akadia.com/services/mysql_survival.html Click here for more information regarding the differences between MyISAM and InnoDB.]&lt;br /&gt;
&lt;br /&gt;
In CSE330, we will be using InnoDB for our primary MySQL storage engine because of its support for foreign key constraints.  However, in your personal applications down the road, feel free to use either InnoDB or MyISAM.&lt;br /&gt;
&lt;br /&gt;
== Installing and Configuring MySQL ==&lt;br /&gt;
&lt;br /&gt;
To use MySQL, you need the MySQL Server package.  Because we will be interacting with MySQL primarily from PHP scripts, we will also need the associated PHP libraries. In '''yum (RHEL)''', you need the packages '''mariadb-server''' and '''php-mbstring''', and from '''amazon-linux-extras''', you need the package '''lamp-mariadb10.2-php7.2'''. If you're wondering what MariaDB is, it is a fork of MySQL server that is recommended by Amazon for use with Linux 2 AMI systems. For our purposes, MariaDB and MySQL are effectively identical.&lt;br /&gt;
&lt;br /&gt;
To install these packages from their respective package repositories, run the following two commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum install -y mariadb-server php-mbstring&lt;br /&gt;
$ sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to restart Apache after installing any packages relating to your web server!&lt;br /&gt;
&lt;br /&gt;
Run these commands to start the server and the client automatically on startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo systemctl start mariadb&lt;br /&gt;
$ sudo systemctl enable mariadb&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the following command to set the MySQL root user password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mysqladmin -u root password&lt;br /&gt;
New password: &lt;br /&gt;
Confirm new password: &lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When it asks, type the new password, press Enter, and then type the new password again.  You cannot see what you are typing because a password is supposed to be secret.  If the shell displayed the password to you while you were typing it, it would be forever saved in ''~/.bash_history''!&lt;br /&gt;
&lt;br /&gt;
== Using MySQL from the Command Line ==&lt;br /&gt;
&lt;br /&gt;
To interface with MySQL/MariaDB from the command line, use the &amp;lt;code&amp;gt;mysql&amp;lt;/code&amp;gt; command.  The syntax is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mysql -u USERNAME -p DATABASENAME&lt;br /&gt;
Welcome to the MariaDB monitor. ...&lt;br /&gt;
&lt;br /&gt;
MariaDB [(DATABASENAME)]&amp;gt; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''-u''' argument specifies a specific user to use MySQL/MariaDB with, and the '''-p''' argument specifies that you would like to use a password to login to that user. If you add the '''-p''' argument, you will be prompted for the password associated with USERNAME. Failing to provide the '''-p''' is the same as attempting to log in with no password. '''DATABASENAME''' is optional; if this is your first time using MySQL from the command line, you should probably leave this blank.&lt;br /&gt;
&lt;br /&gt;
== Managing Databases ==&lt;br /&gt;
&lt;br /&gt;
To create a database on your MySQL server, simply run the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create database DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can delete a database using the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
drop database DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you're at the MySQL prompt, use the following query to select a database to which to run select, insert, update, and delete queries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
use DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL User Management ==&lt;br /&gt;
&lt;br /&gt;
The first time you log into MySQL, you will need to use the root user, with the password that you specified earlier.  However, it is unwise to use the root user for everyday operations with your MySQL database.&lt;br /&gt;
&lt;br /&gt;
=== Creating a New User ===&lt;br /&gt;
&lt;br /&gt;
To create a new user named USERNAME with the password PASSWORD, run the following query inside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create user 'USERNAME'@'localhost' identified by 'PASSWORD';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create USERNAME, but that user will not have privileges to access any databases.&lt;br /&gt;
&lt;br /&gt;
=== Granting Privileges ===&lt;br /&gt;
&lt;br /&gt;
MySQL provides the '''grant''' command to grant privileges to a user.  The syntax for assigning USERNAME some PRIVILEGES on a TABLE in a DATABASE is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant PRIVILEGES on DATABASE.TABLE to USERNAME@'localhost';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to grant global privileges to a certain administrative user, run the query like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant all on *.* to USERNAME@'localhost' with grant option;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ''with grant option'' enables this user to create other users and assign them permissions, like we are doing here.&lt;br /&gt;
&lt;br /&gt;
If you want to grant privileges to a certain user so that they can only manipulate data in a certain database (a wise idea for when you create a user to use in your PHP web application), run the query like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant select,insert,update,delete on DATABASE.* to USERNAME@'localhost';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever you change privileges, you also need to run the query &amp;lt;code&amp;gt;flush privileges;&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
flush privileges;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== phpMyAdmin ==&lt;br /&gt;
&lt;br /&gt;
It is often cumbersome to SSH into your server every time you want to interact with your database.  A popular web-based window into your MySQL server is '''phpMyAdmin'''.&lt;br /&gt;
&lt;br /&gt;
=== Installing phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
To add phpMyAdmin to apache's root server, you need to make your user apart of the apache group, and change the owner of the root directory to apache.&lt;br /&gt;
&lt;br /&gt;
To add your user to the apache group:&lt;br /&gt;
 $ sudo usermod -a -G apache YOUR_USERNAME&lt;br /&gt;
'''Note you may have to exit your server and ssh back in for this to take effect'''&lt;br /&gt;
&lt;br /&gt;
Change the owner of the www folders to your user, and the group apache&lt;br /&gt;
 $ sudo chown -R YOUR_USERNAME:apache /var/www&lt;br /&gt;
&lt;br /&gt;
'''Now that you can access the /var/www/html directory''' download phpMyAdmin to apache's root directory using '''wget''', and then extract it using '''tar -xzvf''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd /var/www/html&lt;br /&gt;
$ wget 'https://files.phpmyadmin.net/phpMyAdmin/4.9.4/phpMyAdmin-4.9.4-all-languages.tar.gz'&lt;br /&gt;
&lt;br /&gt;
$ ls&lt;br /&gt;
phpMyAdmin-4.9.4-all-languages.tar.gz&lt;br /&gt;
&lt;br /&gt;
$ mkdir phpmyadmin &amp;amp;&amp;amp; tar -xvzf phpMyAdmin-4.9.4-all-languages.tar.gz -C phpmyadmin --strip-components 1&lt;br /&gt;
&lt;br /&gt;
$ ls&lt;br /&gt;
phpmyadmin  phpMyAdmin-4.9.4-all-languages.tar.gz&lt;br /&gt;
&lt;br /&gt;
$ rm phpMyAdmin-4.9.4-all-languages.tar.gz&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, create a phpMyAdmin configuration file, which needs to be saved as '''config.inc.php'''.  The easiest way to do this is to copy the '''config.sample.inc.php''' file that is included with your download.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd /var/www/html/phpmyadmin&lt;br /&gt;
$ sudo cp config.sample.inc.php config.inc.php&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, open config.inc.php in your favorite text editor (if you forgot how, refer to [[Linux#File Editors|the Linux guide]]), and edit the following line, putting in something random for &amp;quot;mySecretHere&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $cfg['blowfish_secret'] = 'mySecretHere';&lt;br /&gt;
&lt;br /&gt;
Finally, restart Apache, and you're good to go.  phpMyAdmin will be accessible via http://ec2-blah-blah.compute-1.amazonaws.com/phpmyadmin/&lt;br /&gt;
&lt;br /&gt;
===== Troubleshooting =====&lt;br /&gt;
&lt;br /&gt;
Older versions of the phpmyadmin package in apt required that you perform one additional step: let Apache know that phpMyAdmin was installed.  The new version does this automatically so long as you check the &amp;quot;apache&amp;quot; box in the first step of the instalation process.&lt;br /&gt;
&lt;br /&gt;
To manually hook up phpMyAdmin with Apache, run the following command to symlink ''phpmyadmin.conf'' into Apache's ''conf.d'' directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf&lt;br /&gt;
$ sudo apache2ctl restart  # restart Apache&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Once phpMyAdmin is installed, you will see a login screen.  Log in using a non-root username and password you set up in the previous section.  Once inside, you will see a GUI for interacting with your MySQL database.&lt;br /&gt;
&lt;br /&gt;
Even with the GUI, it is often easier to run queries manually, especially when doing operations like creating a table.  To run a query manually, click either the &amp;quot;SQL&amp;quot; tab or the little icon in the toolbar on the upper-left-hand side of the screen that looks like a database cluster (it's third from the left).&lt;br /&gt;
&lt;br /&gt;
== MySQL Schema and State ==&lt;br /&gt;
&lt;br /&gt;
Read the [[MySQL Schema and State]] guide for more information.&lt;br /&gt;
&lt;br /&gt;
== Using MySQL in PHP ==&lt;br /&gt;
&lt;br /&gt;
Read the [[PHP and MySQL]] guide for more information.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Introduction_to_MySQL&amp;diff=2778</id>
		<title>Introduction to MySQL</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Introduction_to_MySQL&amp;diff=2778"/>
		<updated>2021-01-23T22:31:58Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Installing and Configuring MySQL */  Changed instructions to install MariaDB for Linux 2 AMI&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article is an introduction to MySQL, a database used in conjunction with web applications.&lt;br /&gt;
&lt;br /&gt;
== Why Use a Database? ==&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a web site that used flatfiles to keep track of usernames and uploaded file associations.  However, flatfiles are insecure, lack complex logic, and are impractical for a large-scale web application.  This is where databases come in.  Databases are designed from the ground up to be fast, efficient, and powerful storage solutions for any amount of data.&lt;br /&gt;
&lt;br /&gt;
In CSE330, we will be using '''MySQL''', which is a popular, open-source ''relational database management system'' for web applications.&lt;br /&gt;
&lt;br /&gt;
== Database Structure ==&lt;br /&gt;
&lt;br /&gt;
A MySQL server consists of ''databases'', each of which contains ''tables''.  Tables, in turn, consist of one or more ''fields'' (like columns), and the data is stored in one or more ''entries'' (like rows).  A field in a table can be designated as an ''index''; that is, something that can be used to look up the information in the database.  The set of tables, fields, and indices in your database is called your ''schema''.&lt;br /&gt;
&lt;br /&gt;
MySQL uses the '''Structured Query Language (SQL)''' for manipulating data.&lt;br /&gt;
&lt;br /&gt;
=== Storage Engines ===&lt;br /&gt;
&lt;br /&gt;
MySQL is a database server, but under the hood, it actually uses a '''storage engine''' to retrieve the data.  Two storage engines that are popular in the MySQL community are '''InnoDB''' and '''MyISAM'''.  MyISAM is slightly faster than InnoDB, and it specializes in database schemas that involve predominantly ''SELECT'' and ''INSERT'' queries (which you will learn about later).  However, MyISAM lacks InnoDB's power in making relations between tables, and MyISAM also does not support InnoDB's database transactions.  [http://www.akadia.com/services/mysql_survival.html Click here for more information regarding the differences between MyISAM and InnoDB.]&lt;br /&gt;
&lt;br /&gt;
In CSE330, we will be using InnoDB for our primary MySQL storage engine because of its support for foreign key constraints.  However, in your personal applications down the road, feel free to use either InnoDB or MyISAM.&lt;br /&gt;
&lt;br /&gt;
== Installing and Configuring MySQL ==&lt;br /&gt;
&lt;br /&gt;
To use MySQL, you need the MySQL Server package.  Because we will be interacting with MySQL primarily from PHP scripts, we will also need the associated PHP libraries. In '''yum (RHEL)''', you need the packages '''mariadb-server''' and '''php-mbstring''', and from '''amazon-linux-extras''', you need the package '''lamp-mariadb10.2-php7.2'''. If you're wondering what MariaDB is, it is a fork of MySQL server that is recommended by Amazon for use with Linux 2 AMI systems. For our purposes, MariaDB and MySQL are effectively identical.&lt;br /&gt;
&lt;br /&gt;
To install these packages from their respective package repositories, run the following two commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum install -y mariadb-server php-mbstring&lt;br /&gt;
$ sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to restart Apache after installing any packages relating to your web server!&lt;br /&gt;
&lt;br /&gt;
Run these commands to start the server and the client automatically on startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo systemctl start mariadb&lt;br /&gt;
$ sudo systemctl enable mariadb&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the following command to set the MySQL root user password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mysqladmin -u root password&lt;br /&gt;
New password: &lt;br /&gt;
Confirm new password: &lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When it asks, type the new password, press Enter, and then type the new password again.  You cannot see what you are typing because a password is supposed to be secret.  If the shell displayed the password to you while you were typing it, it would be forever saved in ''~/.bash_history''!&lt;br /&gt;
&lt;br /&gt;
== Using MySQL from the Command Line ==&lt;br /&gt;
&lt;br /&gt;
To interface with MySQL from the command line, use the &amp;lt;code&amp;gt;mysql&amp;lt;/code&amp;gt; command.  The syntax is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mysql -u USERNAME -p DATABASENAME&lt;br /&gt;
Welcome to the MySQL monitor. ...&lt;br /&gt;
&lt;br /&gt;
mysql&amp;gt; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted for the password associated with USERNAME.&lt;br /&gt;
&lt;br /&gt;
== Managing Databases ==&lt;br /&gt;
&lt;br /&gt;
To create a database on your MySQL server, simply run the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create database DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can delete a database using the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
drop database DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you're at the MySQL prompt, use the following query to select a database to which to run select, insert, update, and delete queries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
use DATABASENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL User Management ==&lt;br /&gt;
&lt;br /&gt;
The first time you log into MySQL, you will need to use the root user, with the password that you specified earlier.  However, it is unwise to use the root user for everyday operations with your MySQL database.&lt;br /&gt;
&lt;br /&gt;
=== Creating a New User ===&lt;br /&gt;
&lt;br /&gt;
To create a new user named USERNAME with the password PASSWORD, run the following query inside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create user 'USERNAME'@'localhost' identified by 'PASSWORD';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create USERNAME, but that user will not have privileges to access any databases.&lt;br /&gt;
&lt;br /&gt;
=== Granting Privileges ===&lt;br /&gt;
&lt;br /&gt;
MySQL provides the '''grant''' command to grant privileges to a user.  The syntax for assigning USERNAME some PRIVILEGES on a TABLE in a DATABASE is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant PRIVILEGES on DATABASE.TABLE to USERNAME@'localhost';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to grant global privileges to a certain administrative user, run the query like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant all on *.* to USERNAME@'localhost' with grant option;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ''with grant option'' enables this user to create other users and assign them permissions, like we are doing here.&lt;br /&gt;
&lt;br /&gt;
If you want to grant privileges to a certain user so that they can only manipulate data in a certain database (a wise idea for when you create a user to use in your PHP web application), run the query like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
grant select,insert,update,delete on DATABASE.* to USERNAME@'localhost';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever you change privileges, you also need to run the query &amp;lt;code&amp;gt;flush privileges;&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
flush privileges;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== phpMyAdmin ==&lt;br /&gt;
&lt;br /&gt;
It is often cumbersome to SSH into your server every time you want to interact with your database.  A popular web-based window into your MySQL server is '''phpMyAdmin'''.&lt;br /&gt;
&lt;br /&gt;
=== Installing phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
To add phpMyAdmin to apache's root server, you need to make your user apart of the apache group, and change the owner of the root directory to apache.&lt;br /&gt;
&lt;br /&gt;
To add your user to the apache group:&lt;br /&gt;
 $ sudo usermod -a -G apache YOUR_USERNAME&lt;br /&gt;
'''Note you may have to exit your server and ssh back in for this to take effect'''&lt;br /&gt;
&lt;br /&gt;
Change the owner of the www folders to your user, and the group apache&lt;br /&gt;
 $ sudo chown -R YOUR_USERNAME:apache /var/www&lt;br /&gt;
&lt;br /&gt;
'''Now that you can access the /var/www/html directory''' download phpMyAdmin to apache's root directory using '''wget''', and then extract it using '''tar -xzvf''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd /var/www/html&lt;br /&gt;
$ wget 'https://files.phpmyadmin.net/phpMyAdmin/4.9.4/phpMyAdmin-4.9.4-all-languages.tar.gz'&lt;br /&gt;
&lt;br /&gt;
$ ls&lt;br /&gt;
phpMyAdmin-4.9.4-all-languages.tar.gz&lt;br /&gt;
&lt;br /&gt;
$ mkdir phpmyadmin &amp;amp;&amp;amp; tar -xvzf phpMyAdmin-4.9.4-all-languages.tar.gz -C phpmyadmin --strip-components 1&lt;br /&gt;
&lt;br /&gt;
$ ls&lt;br /&gt;
phpmyadmin  phpMyAdmin-4.9.4-all-languages.tar.gz&lt;br /&gt;
&lt;br /&gt;
$ rm phpMyAdmin-4.9.4-all-languages.tar.gz&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, create a phpMyAdmin configuration file, which needs to be saved as '''config.inc.php'''.  The easiest way to do this is to copy the '''config.sample.inc.php''' file that is included with your download.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd /var/www/html/phpmyadmin&lt;br /&gt;
$ sudo cp config.sample.inc.php config.inc.php&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, open config.inc.php in your favorite text editor (if you forgot how, refer to [[Linux#File Editors|the Linux guide]]), and edit the following line, putting in something random for &amp;quot;mySecretHere&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $cfg['blowfish_secret'] = 'mySecretHere';&lt;br /&gt;
&lt;br /&gt;
Finally, restart Apache, and you're good to go.  phpMyAdmin will be accessible via http://ec2-blah-blah.compute-1.amazonaws.com/phpmyadmin/&lt;br /&gt;
&lt;br /&gt;
===== Troubleshooting =====&lt;br /&gt;
&lt;br /&gt;
Older versions of the phpmyadmin package in apt required that you perform one additional step: let Apache know that phpMyAdmin was installed.  The new version does this automatically so long as you check the &amp;quot;apache&amp;quot; box in the first step of the instalation process.&lt;br /&gt;
&lt;br /&gt;
To manually hook up phpMyAdmin with Apache, run the following command to symlink ''phpmyadmin.conf'' into Apache's ''conf.d'' directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf&lt;br /&gt;
$ sudo apache2ctl restart  # restart Apache&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Once phpMyAdmin is installed, you will see a login screen.  Log in using a non-root username and password you set up in the previous section.  Once inside, you will see a GUI for interacting with your MySQL database.&lt;br /&gt;
&lt;br /&gt;
Even with the GUI, it is often easier to run queries manually, especially when doing operations like creating a table.  To run a query manually, click either the &amp;quot;SQL&amp;quot; tab or the little icon in the toolbar on the upper-left-hand side of the screen that looks like a database cluster (it's third from the left).&lt;br /&gt;
&lt;br /&gt;
== MySQL Schema and State ==&lt;br /&gt;
&lt;br /&gt;
Read the [[MySQL Schema and State]] guide for more information.&lt;br /&gt;
&lt;br /&gt;
== Using MySQL in PHP ==&lt;br /&gt;
&lt;br /&gt;
Read the [[PHP and MySQL]] guide for more information.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Apache&amp;diff=2777</id>
		<title>Apache</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Apache&amp;diff=2777"/>
		<updated>2021-01-23T22:03:24Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Installing Apache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''Apache'' is the industry standard web server for Linux distributions.  It is highly configurable and has a wide range of modules ready for different needs.&lt;br /&gt;
&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=permanence&lt;br /&gt;
|id=910&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== What is a web server? ==&lt;br /&gt;
&lt;br /&gt;
A web server is software that listens for connections to your machine, and when a connection is receive, processes the request and responds with the appropriate information.  Most web servers listen on port 80, which is reserved for the purpose, and use the HTTP protocol.&lt;br /&gt;
&lt;br /&gt;
For example, when you visit this wiki, you are sending a request over the internet to some machine that is probably located somewhere in EIT (the user seldom knows exactly where the machine is located).  The web server receives your request, and it processes the data you sent.  Finally, the server prepares a response (the web page), and sends it back to you.&lt;br /&gt;
&lt;br /&gt;
== Installing Apache ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
In yum, Apache is distributed under the package name '''httpd''' (for ''hypertext transfer protocol daemon'').  Use the package manager associated with your distribution to install Apache.  (For more information on how to use yum, see [[Linux#Repository-Based Package Managers|the Linux guide]].)&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum update&lt;br /&gt;
$ sudo yum install httpd&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You'll need to run this command to add Apache as a startup item:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo /sbin/chkconfig --levels 235 httpd on&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In RHEL, most Apache configurations are stored in ''/etc/httpd/conf/httpd.conf'' and others are located in the directory ''/etc/httpd/conf.d/''.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Apache Directives ==&lt;br /&gt;
&lt;br /&gt;
You define your settings for Apache using ''directives''.  Some of the directives you will likely encounter include:&lt;br /&gt;
&lt;br /&gt;
* '''DocumentRoot:''' The path to the directory where the top level web files are going to be stored.&lt;br /&gt;
* '''IfModule:'''  The following block would be included if specified module exists.&lt;br /&gt;
* '''User:''' Which user apache2 will run as.&lt;br /&gt;
* '''Group:''' Which group will have group access to default web files.&lt;br /&gt;
* '''AccessFileName:''' The name of the access file (that specifies user names/passwords and other limitations to files/directories).&lt;br /&gt;
* '''ErrorLog:''' Where any errors will be written.&lt;br /&gt;
* '''Include:''' Include some other files.&lt;br /&gt;
* '''LogFormat:''' How to write a log message.&lt;br /&gt;
* '''ErrorDocument:''' Files to display for some HTTP errors (500, 404, 402 etc.).&lt;br /&gt;
* '''Alias:''' Map a directory URL to some other location on your filesystem.  Requires that the ''Alias'' module be loaded.&lt;br /&gt;
&lt;br /&gt;
=== .htaccess Files ===&lt;br /&gt;
&lt;br /&gt;
You can also specify some Apache configurations without delving into the master configuration file.  To do this, put a file named ''.htaccess'' in any directory that Apache is serving.  All directives in it will be interpreted as if they were in a Directory directive in the master configuration file.&lt;br /&gt;
&lt;br /&gt;
'''VERY IMPORTANT:''' The directory containing ''.htaccess'' must not have the '''AllowOverride None''' directive in the master configuration file in order for '''.htaccess''' to be read.&lt;br /&gt;
=== Directory Directive ===&lt;br /&gt;
&lt;br /&gt;
Use the Directory directive to assign other directives to a specific directory.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Directory /var/www/&amp;gt;&lt;br /&gt;
	Options Indexes FollowSymLinks &lt;br /&gt;
	AllowOverride None&lt;br /&gt;
	Order allow,deny&lt;br /&gt;
	allow from all&lt;br /&gt;
	RedirectMatch ^/$ /apache2-default/&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets options for the ''/var/www'' directory.&lt;br /&gt;
# The '''Options''' directive says that:&lt;br /&gt;
## If no index page is present in a directory, display a directory index page instead&lt;br /&gt;
## Apache will follow symbolic links in the directory&lt;br /&gt;
# '''AllowOverride None''' says that ''.htaccess'' files cannot alter the Apache options in this directory and all sub-directories&lt;br /&gt;
# '''Order allow,deny''' and '''Allow from all''' specifies that anybody is allowed to access this server via HTTP.&lt;br /&gt;
&lt;br /&gt;
Note that this directory is actually the root directory of the web server.&lt;br /&gt;
&lt;br /&gt;
== The UserDir Module ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
The UserDir module lets you access files for any user on the server with a ~, e.g., http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/~paul/&lt;br /&gt;
&lt;br /&gt;
This module comes installed, but not activated by default.&lt;br /&gt;
&lt;br /&gt;
=== Enabling UserDir in RHEL ===&lt;br /&gt;
&lt;br /&gt;
If you are using an RHEL-based distribution for your server (like the Amazon AMI), you need to edit the master Apache configuration file.&lt;br /&gt;
&lt;br /&gt;
Open ''/etc/httpd/conf.d/userdir.conf'' in your favorite text editor.  For more information on command-line text editors, refer to [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
Find the line that says&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir disabled&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and change it to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir disabled root&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, find the line that says&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;#UserDir public_html&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and uncomment it; that is, remove the # so that you have&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir public_html&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells Apache that the directory containing each user's html files is a subdirectory of their home directory called public_html.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Users need to manually create public_html.  It is not created automatically.&lt;br /&gt;
&lt;br /&gt;
You may also need to change the permissions of your user directory and your public_html directory to allow Apache to read and execute inside them.  To do this, run the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo chmod o+x /home/myusername&lt;br /&gt;
$ sudo chmod o+rx /home/myusername/public_html&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, [[#Restarting Apache and Testing|restart Apache]].&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Remapping UserDir ===&lt;br /&gt;
&lt;br /&gt;
If you want to change the name of the UserDir web server root from '''public_html''' to something else like '''.html''', follow these instructions.  (You do not need to do this for the purposes of CSE 330; this serves as a reference.)&lt;br /&gt;
&lt;br /&gt;
# Rename your '''public_html''' to '''.html'''&lt;br /&gt;
#* The &amp;quot;.&amp;quot; in front of the directory name means that the directory is a hidden one.  You will not see it with the normal &amp;quot;ls&amp;quot; command.  Use &amp;quot;ls -a&amp;quot; to see hidden files as well.&lt;br /&gt;
# Edit the UserDir configuration file.&lt;br /&gt;
#* In RHEL, edit the userDir configuration file at ''/etc/httpd/conf.d/userdir.conf''&lt;br /&gt;
# Find the line that reads &amp;lt;code&amp;gt;UserDir public_html&amp;lt;/code&amp;gt; and change it to &amp;lt;code&amp;gt;UserDir .html/&amp;lt;/code&amp;gt;&lt;br /&gt;
# [[#Restarting Apache and Testing|Restart Apache]].&lt;br /&gt;
&lt;br /&gt;
== Apache Logs ==&lt;br /&gt;
&lt;br /&gt;
Apache creates two log files: one for all access attempts to your server, and one for errors.  The locations of these log files are:&lt;br /&gt;
&lt;br /&gt;
* '''Access Log:''' /var/log/httpd/access_log&lt;br /&gt;
* '''Error Log:''' /var/log/httpd/error_log&lt;br /&gt;
&lt;br /&gt;
You might find it helpful to see access and errors appear &amp;quot;live&amp;quot; in your terminal window as they are created.  To do this, you can use the [[Linux#Command Reference|tail -f]] command.  Since the log files have strict permissions, you will need to also use sudo.  Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo tail -f /var/log/httpd/access_log&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Virtual Hosts ==&lt;br /&gt;
&lt;br /&gt;
'''Virtual Hosts''' are used to run multiple Apache web servers from the same machine.  Virtual hosts can listen for connections on different ports and/or different hostnames, serving completely different web sites to each.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost cse330.dyndns.org&amp;gt;&lt;br /&gt;
	ServerAdmin webmaster@localhost&lt;br /&gt;
	ServerName cse330.dyndns.org&lt;br /&gt;
	DocumentRoot /home/www/cse330/&lt;br /&gt;
	ErrorLog /var/log/httpd/error_log&lt;br /&gt;
	LogLevel warn&lt;br /&gt;
	CustomLog /var/log/apache2/access_log combined&lt;br /&gt;
	ServerSignature On&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration enables any requests that use a host name of ''cse330.dyndns.org'' will use ''/home/www/cse330'' as the root document directory.  Make sure that the DocumentRoot directory exists and is readable by the httpd process.  In RHEL, Apache runs as the '''apache''' user.&lt;br /&gt;
&lt;br /&gt;
It is good practice to put raw server configuration files in ''/etc/httpd/sites-available''.  To activate a site, create a symlink from the configuration in ''sites-available'' to a sibling directory called ''sites-enabled''.&lt;br /&gt;
&lt;br /&gt;
== Restarting Apache and Testing ==&lt;br /&gt;
&lt;br /&gt;
Whenever you make changes to the Apache configuration files, you will need to restart Apache for the changes to take effect.  There are several different ways to restart Apache; they all functionally do (almost) the same thing, so choose your favorite:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo /usr/sbin/apachectl restart&lt;br /&gt;
$ sudo apachectl restart    # if /usr/sbin is in your PATH (which it is *not* by default in RHEL)&lt;br /&gt;
$ sudo /etc/init.d/httpd restart&lt;br /&gt;
$ sudo /sbin/service httpd restart&lt;br /&gt;
$ sudo service httpd restart&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're torn for which version is the &amp;quot;best&amp;quot; to use, the commands involving '''apachectl''' (think &amp;quot;Apache Control&amp;quot;) are written by the Apache folks themselves.  This has a couple advantages:&lt;br /&gt;
* They show you errors in the startup process (if there are any)&lt;br /&gt;
* They give you the option to perform a &amp;quot;soft&amp;quot; restart; that is, a restart that allows any pending connections to complete.  To perform a soft restart, use ''graceful'': &amp;lt;code&amp;gt;sudo apachectl graceful&amp;lt;/code&amp;gt;&lt;br /&gt;
In my anecdotal experience, the '''apachectl''' commands are also faster than the '''service''' or '''init.d''' commands.&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working, create a test file in your home directory under public_html, and then point your browser to it: http://ec2-xxx-xx-xx-xxx.compute-1.amazonaws.com/~yourUserName/hello.txt&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=PHP&amp;diff=2776</id>
		<title>PHP</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=PHP&amp;diff=2776"/>
		<updated>2021-01-23T22:02:50Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: Changed version of PHP to install to be compatible with Amazon Linux 2 AMI&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PHP is an open-source language used widely for writing server-side code for web servers.  PHP is a good starting point for web developers, as it is straightforward to learn and yet powerful at the same time.  Indeed, some of the internet's most popular web sites (including Facebook and Wikipedia) are written using PHP as their language of choice!  This article introduces the syntax of PHP and how to make a basic PHP web application.&lt;br /&gt;
&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=mac_pc&lt;br /&gt;
|id=934&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== What is PHP? ==&lt;br /&gt;
&lt;br /&gt;
PHP is a server-side scripting language widely used in web development.  PHP is what turns your web site from a static fileserver into a dynamic web application.&lt;br /&gt;
&lt;br /&gt;
By default, Apache only knows how to serve static HTML pages to the client.  You can write as many HTML pages as you want, which is fine for basic web sites.  But if you want to have users post to a forum, or process credit card transactions, or make your own online calendar, a server-side language like PHP is what you need.&lt;br /&gt;
&lt;br /&gt;
=== Document Generation Language ===&lt;br /&gt;
&lt;br /&gt;
If PHP's original core purpose had to be described in three words, it would be this: '''document generation language'''.  Unlike languages including Java, Ruby, Python, and Perl, which consist of classes in a strict program layout, PHP code is most often embedded inside a template document.  When the PHP interpreter runs, it &amp;quot;fills in the gaps&amp;quot; and generates a finished product document.&lt;br /&gt;
&lt;br /&gt;
This isn't to say that PHP can ''only'' be a document generating language, because this is certainly not true.  However, for the purposes of Module 2, it is safe to think of it this way when you are learning the concepts behind a web server.&lt;br /&gt;
&lt;br /&gt;
==== MIME Types ====&lt;br /&gt;
&lt;br /&gt;
By default, PHP generates HTML documents.  (Recall that an HTML document is simply a block of text consisting of markup conforming to the HTML standard.)&lt;br /&gt;
&lt;br /&gt;
However, PHP does not need to generate HTML documents.  It can also generate images, PDFs, or any other type of document.  Each of these document types has its own unique markup language.  The markup language used by a certain document is defined by its ''MIME Type''.&lt;br /&gt;
&lt;br /&gt;
The HTML MIME Type is '''text/html'''.  Other MIME Types include '''image/jpeg''', '''image/png''', and '''application/xml'''.&lt;br /&gt;
&lt;br /&gt;
To change the MIME Type of the document generated by PHP, use the statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
header(&amp;quot;Content-Type: image/jpeg&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since PHP generates HTML documents by default, you can think of there being an implicit &amp;lt;code&amp;gt;header(&amp;quot;Content-Type: text/html&amp;quot;);&amp;lt;/code&amp;gt; at the top of every PHP script.&lt;br /&gt;
&lt;br /&gt;
=== PHP and Apache ===&lt;br /&gt;
&lt;br /&gt;
When you request a PHP file over Apache, the file is ''not'' sent verbatim.  Instead, it is first sent through the PHP interpreter.  Here is an oversimplified schematic of the process:&lt;br /&gt;
&lt;br /&gt;
[[File:PHP-Apache_Flowchart.png]]&lt;br /&gt;
&lt;br /&gt;
In summary, here are some points to keep in mind.&lt;br /&gt;
&lt;br /&gt;
# A PHP file on your server is not an HTML document.  It is a PHP script.&lt;br /&gt;
# PHP generates documents.  By default, it generates HTML documents.&lt;br /&gt;
# PHP can generate other document types by changing the MIME Type in the Content-Type HTTP Header.&lt;br /&gt;
# Apache runs the PHP interpreter on your PHP script before transmitting it to the browser.  The content that is generated after the PHP interpreter runs is expected to match the MIME type: by default, an HTML document.&lt;br /&gt;
# The W3C Validator checks for valid markup in an HTML document.  Everywhere that PHP generates an HTML document, that HTML document should be valid.&lt;br /&gt;
&lt;br /&gt;
== Installing PHP ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
To install PHP 7.2, run the following command to install php7.2 from the Amazon Linux Extras repository. &lt;br /&gt;
  sudo amazon-linux-extras install -y php7.2&lt;br /&gt;
&lt;br /&gt;
Once you install the required packages, [[Web Server Configuration#Restarting Apache and Testing|restart Apache]] for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== PHP Configurations ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
The PHP configuration file is called ''php.ini''.  In RHEL, it is located at ''/etc/php.ini''.&lt;br /&gt;
&lt;br /&gt;
The configuration file is largely self-documenting as to what the different options mean.  There is one value in particular that we want to change for the purposes of CSE330.  Open php.ini in your favorite text editor, find the '''display_errors''' option, and set it to '''On''':&lt;br /&gt;
&lt;br /&gt;
 display_errors = On&lt;br /&gt;
&lt;br /&gt;
You will need to restart Apache for any php.ini changes to take effect.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' You can turn errors on or off for a certain PHP script by using the '''error_reporting()''' and/or '''ini_set()''' functions.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you tell PHP to log its errors, they will be stored in the Apache error log file, at ''/var/log/httpd/error_log''.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Your First PHP Script ==&lt;br /&gt;
&lt;br /&gt;
By default, all files that have the *.php extension will be interpreted as containing PHP code.  &lt;br /&gt;
All files with PHP need to be saved as '.php'; not '.html'.&lt;br /&gt;
Here is the most basic PHP script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
phpinfo();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save that code into a file named phpinfo.php, and save it in your web server directory (/var/www/html/).  Load it up in your browser like this: ''http://ec2-blah-blah.compute-1.amazonaws.com/phpinfo.php''&lt;br /&gt;
&lt;br /&gt;
If you see something like this, your PHP installation is working!&lt;br /&gt;
&lt;br /&gt;
[[Image:Php_info.png]]&lt;br /&gt;
&lt;br /&gt;
Look at the source code of that page.  Notice that even though there were only three lines of code in our PHP file, PHP filled it up with hundreds of lines of HTML!&lt;br /&gt;
&lt;br /&gt;
Your own PHP scripts will probably look something more like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
	&amp;lt;title&amp;gt;My First PHP Script&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &amp;quot;\t&amp;lt;p&amp;gt;Hello World!&amp;lt;/p&amp;gt;\n&amp;quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code will send the following HTML to the browser:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
	&amp;lt;title&amp;gt;My First PHP Script&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;Hello World!&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here's the take-home message of this section.  To run PHP code, enclose it in &amp;lt;code&amp;gt;&amp;lt;?php  ?&amp;gt;&amp;lt;/code&amp;gt; tags; HTML code can be used in a PHP file (although not inside the PHP code block!); and just a few lines of code can generate an arbitrary amount of HTML.&lt;br /&gt;
&lt;br /&gt;
== PHP Language Components ==&lt;br /&gt;
&lt;br /&gt;
PHP is a programming language much like others you have learned: it has variables, arrays, functions, objects etc.  However, the syntax for PHP and the way PHP handles variables may be new to you.  This section gives an overview of PHP the language.&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
All variables start with the currency '''$''' symbol.  The '''$''' is necessary for both setting and accessing.&lt;br /&gt;
&lt;br /&gt;
PHP is a weak-typed language; that is, you can set any type of value to a variable (string, array, number, etc), and PHP will accept it, even if that variable previously contained a different data type.  In some ways this is convenient, but in others it can lead to hard-to-detect bugs, so be careful.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$i = 5;  # Set the integer 5 to the variable $i&lt;br /&gt;
$msg = &amp;quot;Hello World&amp;quot;;  # Set the string Hello World to the variable $msg&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that all lines in PHP necessarily end with a semicolon.  If you forget a semicolon, the PHP will fail to parse!&lt;br /&gt;
&lt;br /&gt;
=== Strings ===&lt;br /&gt;
&lt;br /&gt;
Strings in PHP can be either single-quoted or double-quoted.  Single-quoted strings are always taken literally; double-quoted strings allow for additional elements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$a = &amp;quot;Apple&amp;quot;;&lt;br /&gt;
$b = &amp;quot;Banana&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$fruits_double = &amp;quot;$a\n$b&amp;quot;;   # $fruits_double now contains the string Apple (line break) Banana&lt;br /&gt;
$fruits_single = '$a\n$b';   # $fruits_single now contains the string $a\n$b&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to use special characters in a double-quoted strings, escape them using the backslash operator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$a = &amp;quot;Apple&amp;quot;;&lt;br /&gt;
$b = &amp;quot;Banana&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$fruits = &amp;quot;\$a\\n$b&amp;quot;;   # $fruits now contains the string $a\nBanana&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can concatenate multiple strings together using the concatenation operator, which in php is a period:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$c = &amp;quot;Cherry&amp;quot;;&lt;br /&gt;
$g = &amp;quot;Grapefruit&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$fruits = $c.&amp;quot;\n&amp;quot;.$g;   # $fruits contains the string Cherry (line break) Grapefruit&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Arrays ===&lt;br /&gt;
&lt;br /&gt;
Declaring arrays is very simple in PHP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$fruits = array(&amp;quot;Apple&amp;quot;, &amp;quot;Banana&amp;quot;, &amp;quot;Cherry&amp;quot;, &amp;quot;Grapefruit&amp;quot;);   # $arr now contains an array with 4 items&lt;br /&gt;
&lt;br /&gt;
echo $fruits[1];   # displays Banana&lt;br /&gt;
&lt;br /&gt;
echo count($fruits);   # displays 4&lt;br /&gt;
&lt;br /&gt;
array_shift($fruits);   # remove the first element of the array&lt;br /&gt;
&lt;br /&gt;
echo $fruits[1];   # displays Cherry&lt;br /&gt;
&lt;br /&gt;
echo count($fruits);   # displays 3&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: '''echo''' outputs a string to the browser.  We will see more ways to output data [[#Outputting Data|later in this guide]].&lt;br /&gt;
&lt;br /&gt;
PHP also supports ''associative arrays''.  Associative arrays are arrays whose keys are strings rather than numbers; in some languages, they are called Dictionaries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$fruits[&amp;quot;a&amp;quot;] = &amp;quot;Apple&amp;quot;;&lt;br /&gt;
$fruits[&amp;quot;b&amp;quot;] = &amp;quot;Banana&amp;quot;;&lt;br /&gt;
$fruits[&amp;quot;c&amp;quot;] = &amp;quot;Cherry&amp;quot;;&lt;br /&gt;
$fruits[&amp;quot;g&amp;quot;] = &amp;quot;Grapefruit&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
echo $fruits[&amp;quot;c&amp;quot;];   # displays Cherry&lt;br /&gt;
&lt;br /&gt;
$keys = array_keys($fruits);   # get an array containing indexed values of the fruits' keys&lt;br /&gt;
&lt;br /&gt;
echo $keys[3];   # displays g&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Conditional Statements ===&lt;br /&gt;
&lt;br /&gt;
Conditional statements work similarly to how they do in other languages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$grade = 85;&lt;br /&gt;
&lt;br /&gt;
if ($grade &amp;lt; 60) {&lt;br /&gt;
	echo &amp;quot;F&amp;quot;;&lt;br /&gt;
} elseif ($grade &amp;lt; 70) {&lt;br /&gt;
	echo &amp;quot;D&amp;quot;;&lt;br /&gt;
} elseif ($grade &amp;lt; 80) {&lt;br /&gt;
	echo &amp;quot;C&amp;quot;;&lt;br /&gt;
} elseif ($grade &amp;lt; 90) {&lt;br /&gt;
	echo &amp;quot;B&amp;quot;;&lt;br /&gt;
} else {&lt;br /&gt;
	echo &amp;quot;A&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PHP also supports switch statements, which are convenient for simplifying long if/elseif/else blocks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$food = &amp;quot;Apple&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
switch ($food) {&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;Apple&amp;quot;:&lt;br /&gt;
case &amp;quot;Banana&amp;quot;:&lt;br /&gt;
case &amp;quot;Cherry&amp;quot;:&lt;br /&gt;
case &amp;quot;Grapefruit&amp;quot;:&lt;br /&gt;
	echo &amp;quot;You must like fruit!&amp;quot;;&lt;br /&gt;
	break;&lt;br /&gt;
case &amp;quot;Broccoli&amp;quot;:&lt;br /&gt;
case &amp;quot;Spinach&amp;quot;:&lt;br /&gt;
	echo &amp;quot;You must like vegetables!&amp;quot;;&lt;br /&gt;
	break;&lt;br /&gt;
default:&lt;br /&gt;
	echo &amp;quot;You don't like fruits or vegetables!&amp;quot;;&lt;br /&gt;
	break;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Loops ===&lt;br /&gt;
&lt;br /&gt;
PHP supports several different kinds of loops, including while, for, and foreach:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$mystring = &amp;quot;&amp;quot;;&lt;br /&gt;
$i = 0;&lt;br /&gt;
while ($i &amp;lt; 5) {&lt;br /&gt;
	$mystring .= &amp;quot;Blah&amp;quot;;&lt;br /&gt;
	$i++;&lt;br /&gt;
}&lt;br /&gt;
echo $mystring;   # displays BlahBlahBlahBlahBlah&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$myarray = array(&amp;quot;Apple&amp;quot;, &amp;quot;Banana&amp;quot;, &amp;quot;Cherry&amp;quot;, &amp;quot;Grapefruit&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
# The following two loops are functionally equivalent.&lt;br /&gt;
&lt;br /&gt;
$mystring = &amp;quot;&amp;quot;;&lt;br /&gt;
for($i=0; $i&amp;lt;count($myarray); $i++){&lt;br /&gt;
	$mystring .= $i.&amp;quot;: &amp;quot;.$myarray[$i].&amp;quot;, &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
echo $mystring;   # displays 0: Apple, 1: Banana, 2: Cherry, 3: Grapefruit&lt;br /&gt;
&lt;br /&gt;
$mystring = &amp;quot;&amp;quot;;&lt;br /&gt;
foreach($myarray as $key =&amp;gt; $value){&lt;br /&gt;
	$mystring .= $key.&amp;quot;: &amp;quot;.$value;&lt;br /&gt;
}&lt;br /&gt;
echo $mystring;   #displays 0: Apple, 1: Banana, 2: Cherry, 3: Grapefruit&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
Just like with all modern programming languages, you can define your own functions with PHP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
function add($x, $y){&lt;br /&gt;
	return $x + $y;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo add(3, 5);   # displays 8&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A neat shortcut for PHP is that you can specify default parameter values directly in the argument list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
function sayHello($name=&amp;quot;John Doe&amp;quot;){&lt;br /&gt;
	return &amp;quot;Hello, $name... how do you do?&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo sayHello(&amp;quot;Todd&amp;quot;);   # displays Hello, Todd... how do you do?&lt;br /&gt;
echo sayHello();   # displays Hello, John Doe... how do you do?&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Object-Oriented Programming ===&lt;br /&gt;
&lt;br /&gt;
PHP5 supports object-oriented programming, and many new libraries come as classes rather than simple functions.  Here is an example class definition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class Food {&lt;br /&gt;
	protected $name;&lt;br /&gt;
	&lt;br /&gt;
	function __construct($name){&lt;br /&gt;
		$this-&amp;gt;name = $name;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	static function getDefinition(){&lt;br /&gt;
		return &amp;quot;Food is nourishment for carbon-based lifeforms.&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	function formatName(){&lt;br /&gt;
		return &amp;quot;Gotta love to eat &amp;quot; . $this-&amp;gt;name;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Fruit extends Food {&lt;br /&gt;
	function formatName(){&lt;br /&gt;
		return Food::formatName() . &amp;quot; (fruit)&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$fruit = new Fruit(&amp;quot;Cherry&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
echo $fruit-&amp;gt;formatName() . &amp;quot;\n&amp;quot;;   # displays: Gotta love to eat Cherry (fruit)&lt;br /&gt;
&lt;br /&gt;
echo Fruit::getDefinition() . &amp;quot;\n&amp;quot;;   # displays: Food is nourishment for carbon-based lifeforms.&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Things to notice:&lt;br /&gt;
&lt;br /&gt;
* All methods in a class must be preceded by the function keyword.&lt;br /&gt;
* Static methods require the '''static''' keyword&lt;br /&gt;
* Instance methods can refer to the current instance through the implicit variable '''$this'''&lt;br /&gt;
* To access properties and methods from an instance, use an arrow: '''$instance-&amp;gt;property'''&lt;br /&gt;
* To access static properties and methods from a class, use two colons: '''ClassName::StaticPropertyOrMethod'''&lt;br /&gt;
* Instances of classes are defined using the syntax '''$instance = new ClassName();''' like in Java&lt;br /&gt;
&lt;br /&gt;
== Outputting Data ==&lt;br /&gt;
&lt;br /&gt;
What's the point of a web language if we can't output data?  The most basic method for outputting data is using either the '''echo''' or '''print''' statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &amp;quot;Hello World&amp;quot;;   # outputs Hello World to the browser&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You often find yourself wanting to print all information associated with a variable for debugging purposes.  PHP provides the handy '''var_dump''' function for that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
var_dump($myvar);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Content Type ===&lt;br /&gt;
&lt;br /&gt;
PHP is just a factory for generating documents.  We've so far seen it create HTML documents, but it can just as easily create images, PDFs, or any other type of interpreted file format.  Each of these files formats has a '''MIME Type''' associated with it.  To specify a MIME type for a page served over HTTP, the &amp;lt;code&amp;gt;Content-Type&amp;lt;/code&amp;gt; header must be set.&lt;br /&gt;
&lt;br /&gt;
This brings up an important point.  '''Every PHP document has an implicit &amp;lt;code&amp;gt;Content-Type: text/html&amp;lt;/code&amp;gt; header.'''  This means that by default, PHP will generate HTML documents.  '''The MIME type for a document can be changed using the header() function:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
header(&amp;quot;Content-Type: text/plain&amp;quot;);&lt;br /&gt;
echo time();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above example creates a plain text file containing the current timestamp (number of seconds since January 1, 1970).&lt;br /&gt;
&lt;br /&gt;
For another application of the Content-Type header, see [[#Sending a File to the Browser]]&lt;br /&gt;
&lt;br /&gt;
=== sprintf() ===&lt;br /&gt;
&lt;br /&gt;
Code in PHP that outputs information can get very ugly.  Consider, for example, the following snippet:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$medals = array(&lt;br /&gt;
	&amp;quot;United States&amp;quot; =&amp;gt; array(46, 29, 29),&lt;br /&gt;
	&amp;quot;China&amp;quot; =&amp;gt; array(38, 27, 23),&lt;br /&gt;
	&amp;quot;Russia&amp;quot; =&amp;gt; array(24, 26, 32)&lt;br /&gt;
);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Country&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Gold Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Silver Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Bronze Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
foreach($medals as $country =&amp;gt; $counts){&lt;br /&gt;
	echo &amp;quot;\t&amp;lt;tr&amp;gt;\n\t\t&amp;lt;td&amp;gt;&amp;quot;.htmlentities($country).&amp;quot;&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;&amp;quot;.htmlentities($counts[0]).&amp;quot;&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;&amp;quot;.htmlentities($counts[1]).&amp;quot;&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;&amp;quot;.htmlentities($counts[2]).&amp;quot;&amp;lt;/td&amp;gt;\n\t&amp;lt;/tr&amp;gt;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code will generate the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Country&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Gold Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Silver Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Bronze Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;United States&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;46&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;29&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;29&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;China&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;38&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;27&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;23&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;Russia&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;24&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;26&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;32&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It's not very clear, though, that this is what the PHP code is going to generate.  In particular, the ''echo'' line inside the ''foreach'' loop is 196 jumbled characters!&lt;br /&gt;
&lt;br /&gt;
'''sprintf()''' is a nifty PHP function (with roots in C) that allows us to clean up that code.  We get the same output as above if we use the following PHP instead:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$medals = array(&lt;br /&gt;
	&amp;quot;United States&amp;quot; =&amp;gt; array(46, 29, 29),&lt;br /&gt;
	&amp;quot;China&amp;quot; =&amp;gt; array(38, 27, 23),&lt;br /&gt;
	&amp;quot;Russia&amp;quot; =&amp;gt; array(24, 26, 32)&lt;br /&gt;
);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Country&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Gold Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Silver Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Bronze Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
foreach($medals as $country =&amp;gt; $counts){&lt;br /&gt;
	echo sprintf(&amp;quot;\t&amp;lt;tr&amp;gt;\n\t\t&amp;lt;td&amp;gt;%s&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;%d&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;%d&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;%d&amp;lt;/td&amp;gt;\n\t&amp;lt;/tr&amp;gt;\n&amp;quot;,&lt;br /&gt;
		htmlentities($country),&lt;br /&gt;
		$counts[0],&lt;br /&gt;
		$counts[1],&lt;br /&gt;
		$counts[2]&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is more straightforward and self-explanatory than the first example, and it is also easier to edit and maintain.&lt;br /&gt;
&lt;br /&gt;
Here's how '''sprintf()''' works.  The first argument is a ''format string''.  A format string can contain ''conversion specifications'' for additional data that will be inserted into the format string.  The most common conversion specifications are:&lt;br /&gt;
&lt;br /&gt;
* '''%s''' for a string&lt;br /&gt;
* '''%d''' for a signed integer&lt;br /&gt;
* '''%u''' for an unsigned integer&lt;br /&gt;
* '''%f''' for a floating-point number&lt;br /&gt;
** '''%.2f''' for a floating-point number with 2 decimal places&lt;br /&gt;
* '''%%''' for a literal percentage sign&lt;br /&gt;
&lt;br /&gt;
For more detail on sprintf formats, refer to [http://us.php.net/sprintf the PHP documentation].&lt;br /&gt;
&lt;br /&gt;
The remaining arguments are the data that are inserted into each of the conversion specifications.  In the example above, there are four conversion specifications ('''%s''', '''%d''', '''%d''', and '''%d'''), so '''sprintf()''' takes 4 additional arguments after the format string.&lt;br /&gt;
&lt;br /&gt;
Note that we still need to sanitize string output (using '''htmlentities()''' ) when we are using '''sprintf()'''.  However, since our format string specifies integers for the remaining three arguments, '''sprintf()''' will take care of type casting, so we no longer need to worry about sanitizing the integers.&lt;br /&gt;
&lt;br /&gt;
An additional tip: '''printf()''' is a shortcut for '''echo sprintf()'''.  That is, the following lines are functionally equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$n = 12345.678;&lt;br /&gt;
printf(&amp;quot;%.2f\n&amp;quot;, $n); // prints 12345.68&lt;br /&gt;
echo sprintf(&amp;quot;%.2f\n&amp;quot;, $n); // also prints 12345.68&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Passing Variables ==&lt;br /&gt;
&lt;br /&gt;
Input values can be passed to a script either through the URL request line or through data submitted by a form. Built in arrays $_GET['var'] and $_POST['var'] return the value of ''var'' depending on the access method. As we will see in the next section, values can also be passed through session variables. Finally, you can use cookies to store and retrieve values. &lt;br /&gt;
&lt;br /&gt;
Note that upon submitting a form, the page specified in the form tag's action attribute is loaded (with variables sent via post or get).&lt;br /&gt;
&lt;br /&gt;
=== GET: Passing Variables via URL ===&lt;br /&gt;
&lt;br /&gt;
If you want to pass values in a URL, the format is &amp;lt;nowiki&amp;gt;''http://example.com/yourphpfile.php?var1=value1&amp;amp;var2=value2.....''&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PHP saves URL variables in the associative array '''$_GET'''.&lt;br /&gt;
&lt;br /&gt;
For example, the following PHP document would print a hello message according to a name given in the URL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$name = $_GET['name'];&lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;&amp;lt;p&amp;gt;Hello, %s; how do you do?&amp;lt;/p&amp;gt;\n&amp;quot;,&lt;br /&gt;
	htmlentities($name)&lt;br /&gt;
);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you access the URL like this: ''greeting.php?name=Alice'', it will show ''Hello, Alice; how do you do?''&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Before we output the name, we pass it through '''htmlentities()''', which sanitizes it for output to the HTML document.  This is necessary because if we displayed the name verbatim from the URL, the name could be ''anything'': that includes malicious code that could be run on a victim's computer!  You will learn more about this type of cyberattack, called '''Cross-Site Scripting''', in Module 4.  For now, just know that whenever you display anything to the end user, you need to pass it through '''htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
=== POST: Passing Variables via Form ===&lt;br /&gt;
&lt;br /&gt;
Another method for passing variables from page to page is by sending it via POST variables.  Like with GET, POST variables are saved in an associative array, this time named '''$_POST'''.&lt;br /&gt;
&lt;br /&gt;
Consider the following form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;info.php&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;firstnameinput&amp;quot;&amp;gt;First Name:&amp;lt;/label&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;firstname&amp;quot; id=&amp;quot;firstnameinput&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;lastnameinput&amp;quot;&amp;gt;Last Name:&amp;lt;/label&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lastname&amp;quot; id=&amp;quot;lastnameinput&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;birthyearinput&amp;quot;&amp;gt;Birth Year:&amp;lt;/label&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;number&amp;quot; name=&amp;quot;birthyear&amp;quot; id=&amp;quot;birthyearinput&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;strong&amp;gt;Gender:&amp;lt;/strong&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;gender&amp;quot; value=&amp;quot;male&amp;quot; id=&amp;quot;maleinput&amp;quot; /&amp;gt; &amp;lt;label for=&amp;quot;maleinput&amp;quot;&amp;gt;Male&amp;lt;/label&amp;gt; &amp;amp;nbsp;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;gender&amp;quot; value=&amp;quot;female&amp;quot; id=&amp;quot;femaleinput&amp;quot; /&amp;gt; &amp;lt;label for=&amp;quot;femaleinput&amp;quot;&amp;gt;Female&amp;lt;/label&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Send&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;reset&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information on the HTML markup in the above example, refer to [[HTML and CSS|the HTML and CSS guide]].&lt;br /&gt;
&lt;br /&gt;
This submits a form with POST data to '''info.php'''.  Inside '''info.php''', the provided values will be available in the associative $_POST array under the keys ''firstname'', ''lastname'', ''birthyear'', and ''gender''.&lt;br /&gt;
&lt;br /&gt;
To display the submitted input on a target page, '''info.php''' could contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Person Information&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$first = $_POST['firstname'];&lt;br /&gt;
$last = $_POST['lastname'];&lt;br /&gt;
$birthyear = (int) $_POST['birthyear'];&lt;br /&gt;
$gender = $_POST['gender'];&lt;br /&gt;
$age = 2012 - $birthyear;&lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;&amp;lt;p&amp;gt;Hello, %s %s!  You were born in %d, so you are %d years old.  You are %s.&amp;lt;/p&amp;gt;\n&amp;quot;,&lt;br /&gt;
	htmlentities($first),&lt;br /&gt;
	htmlentities($last),&lt;br /&gt;
	$birthyear,&lt;br /&gt;
	$age,&lt;br /&gt;
	htmlentities($gender)&lt;br /&gt;
);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' It is ''very'' important that you always sanitize strings that you output to the browser using '''htmlentities()''' or a similar function.  If you don't, your site will be vulnerable to all sorts of malware.  For more information, refer to the [[Web Application Security, Part 1|Web Application Security]] guide.&lt;br /&gt;
&lt;br /&gt;
For further help with using HTML forms with PHP, we recommend [http://www.tizag.com/phpT/forms.php this tutorial].&lt;br /&gt;
&lt;br /&gt;
=== Self-Submitting Forms ===&lt;br /&gt;
&lt;br /&gt;
Oftentimes we don't want to pass form values to a different page, but rather to the same page as contains the form so that we can process the information and display output on that same page.  To do this, you can simply omit the '''action''' parameter from the form.  Alternatively, you can use a PHP environment variable like $_SERVER['PHP_SELF'].&lt;br /&gt;
&lt;br /&gt;
The following example simply takes the data input from a form and, via POST variables, echoes it back to the user as bold text on the same page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Bold Printer&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;&amp;lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&amp;gt;&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;name&amp;quot;&amp;gt;Name:&amp;lt;/label&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;name&amp;quot; id=&amp;quot;name&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Print in Bold&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
if(isset($_POST['name'])){&lt;br /&gt;
	printf(&amp;quot;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;%s&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;\n&amp;quot;,&lt;br /&gt;
		htmlentities($_POST['name'])&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sessions ==&lt;br /&gt;
&lt;br /&gt;
If you need to keep track of information associated with a user between page loads, you should use a ''session''.  Sessions are excellent for keeping track of the currently-logged-in user, for example.&lt;br /&gt;
&lt;br /&gt;
PHP makes session management dirt simple.  Whenever you need to use session variables, simply call '''session_start()'''.  Then, you may interact with the $_SESSION associative array, and PHP will take care of accessing and saving all session variables for you!&lt;br /&gt;
&lt;br /&gt;
For example, the following page will display a number, and then double that number on each page reload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
session_start();&lt;br /&gt;
 &lt;br /&gt;
$oldnum = (int) @$_SESSION['inc_num'];&lt;br /&gt;
if($oldnum&amp;lt;1) $oldnum=1;&lt;br /&gt;
$newnum = $oldnum*2;&lt;br /&gt;
 &lt;br /&gt;
echo $newnum;&lt;br /&gt;
$_SESSION['inc_num'] = $newnum;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sessions also work across different pages, as long as they are on the same web server.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' To log out a user, you can call '''session_destroy()''' after '''session_start()''' on the logout page.&lt;br /&gt;
&lt;br /&gt;
== Other PHP Tips ==&lt;br /&gt;
&lt;br /&gt;
=== Redirecting to a Different Page ===&lt;br /&gt;
&lt;br /&gt;
If you want to redirect the user to a different page, you need to send a '''Location''' header.  For example, a page containing only this code would redirect the user to the ''login.php'' file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
header(&amp;quot;Location: login.php&amp;quot;);&lt;br /&gt;
exit;   // we call exit here so that the script will stop executing before the connection is broken&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is often useful to perform redirects after you perform server-side operations.&lt;br /&gt;
&lt;br /&gt;
'''Important:''' You should generally not leave a user sitting on a page that has POST data, because if they refresh the page, their POST data will be submitted again, causing your server to perform an action twice.  Rather, you should perform the operation, and then redirect them to another page that does not contain POST data in the header.&lt;br /&gt;
&lt;br /&gt;
=== Reading a File Line-by-Line ===&lt;br /&gt;
&lt;br /&gt;
If you want to read a file line-by-line, open a file handler using '''fopen()''', use '''fgets()''' to read lines until you've reached the end, and then close the file using '''fclose()'''.&lt;br /&gt;
&lt;br /&gt;
The following example reads '''file_with_lines.txt''' and outputs its content in an unordered list, where each list item is a line in the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$h = fopen(&amp;quot;file_with_lines.txt&amp;quot;, &amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$linenum = 1;&lt;br /&gt;
echo &amp;quot;&amp;lt;ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
while( !feof($h) ){&lt;br /&gt;
	printf(&amp;quot;\t&amp;lt;li&amp;gt;Line %d: %s&amp;lt;/li&amp;gt;\n&amp;quot;,&lt;br /&gt;
		$linenum++,&lt;br /&gt;
		fgets($h)&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;&amp;lt;/ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
fclose($h);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Most files in Linux end with an empty line, so the very last iteration of the above loop will output an empty bullet point.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The function '''fgets()''' reads the contents of a line ''in addition to the line feed at the end of the line''.  If you want to compare a string to the line that was read by '''fgets()''', you need to pass the value returned by '''fgets()''' to a function like '''[http://php.net/trim trim()]'''.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you want to read an entire file, PHP provides the '''file_get_contents()''' function, which is basically a shortcut for '''fopen()''', '''fread()''', and '''fclose()'''.  ('''fread()''' is similar to '''fgets()''', except it reads the entire file instead of just one line.)&lt;br /&gt;
&lt;br /&gt;
=== Sending a File to the Browser ===&lt;br /&gt;
&lt;br /&gt;
Another useful function to know is the '''readfile''' function. It takes a file on the webserver's file system and sends it to the web browser. A simple example is given below, but note that you'll probably need to specify addition header fields in order to have the web browser download the file correctly.&lt;br /&gt;
&lt;br /&gt;
The following example loads a file associated with a certain username and displays it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
session_start();&lt;br /&gt;
&lt;br /&gt;
$filename = $_GET['file'];&lt;br /&gt;
&lt;br /&gt;
// We need to make sure that the filename is in a valid format; if it's not, display an error and leave the script.&lt;br /&gt;
// To perform the check, we will use a regular expression.&lt;br /&gt;
if( !preg_match('/^[\w_\.\-]+$/', $filename) ){&lt;br /&gt;
	echo &amp;quot;Invalid filename&amp;quot;;&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Get the username and make sure that it is alphanumeric with limited other characters.&lt;br /&gt;
// You shouldn't allow usernames with unusual characters anyway, but it's always best to perform a sanity check&lt;br /&gt;
// since we will be concatenating the string to load files from the filesystem.&lt;br /&gt;
$username = $_SESSION['username'];&lt;br /&gt;
if( !preg_match('/^[\w_\-]+$/', $username) ){&lt;br /&gt;
	echo &amp;quot;Invalid username&amp;quot;;&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$full_path = sprintf(&amp;quot;/srv/uploads/%s/%s&amp;quot;, $username, $filename);&lt;br /&gt;
&lt;br /&gt;
// Now we need to get the MIME type (e.g., image/jpeg).  PHP provides a neat little interface to do this called finfo.&lt;br /&gt;
$finfo = new finfo(FILEINFO_MIME_TYPE);&lt;br /&gt;
$mime = $finfo-&amp;gt;file($full_path);&lt;br /&gt;
&lt;br /&gt;
// Finally, set the Content-Type header to the MIME type of the file, and display the file.&lt;br /&gt;
header(&amp;quot;Content-Type: &amp;quot;.$mime);&lt;br /&gt;
header('content-disposition: inline; filename=&amp;quot;'.$filename.'&amp;quot;;');&lt;br /&gt;
readfile($full_path);&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uploading a File ===&lt;br /&gt;
&lt;br /&gt;
Uploading files is similar to submitting data in forms.  For starters, you need a form that submits to your uploading script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form enctype=&amp;quot;multipart/form-data&amp;quot; action=&amp;quot;uploader.php&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;MAX_FILE_SIZE&amp;quot; value=&amp;quot;20000000&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;uploadfile_input&amp;quot;&amp;gt;Choose a file to upload:&amp;lt;/label&amp;gt; &amp;lt;input name=&amp;quot;uploadedfile&amp;quot; type=&amp;quot;file&amp;quot; id=&amp;quot;uploadfile_input&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Upload File&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that we need to specify &amp;lt;code&amp;gt;enctype=&amp;quot;multipart/form-data&amp;quot;&amp;lt;/code&amp;gt; on the form.  This is to enable files to be uploaded and recognized by PHP.&lt;br /&gt;
&lt;br /&gt;
PHP puts all files submitted with a form into the '''$_FILES''' superglobal array.  Each entry in the $_FILES array contains the following information:&lt;br /&gt;
&lt;br /&gt;
* '''$_FILES['uploadedfile']['name']''' is the original name of the file on the client's machine&lt;br /&gt;
* '''$_FILES['uploadedfile']['type']''' is the MIME type of the file according to the browser (don't take it for granted)&lt;br /&gt;
* '''$_FILES['uploadedfile']['size']''' is the size, in bytes, of the uploaded file&lt;br /&gt;
* '''$_FILES['uploadedfile']['tmp_name']''' is the temporary location on your filesystem where Apache saved the uploaded file&lt;br /&gt;
* '''$_FILES['uploadedfile']['error']''' is the error code associated with the file upload (if applicable)&lt;br /&gt;
&lt;br /&gt;
To upload the file submitted by the form above in a user's special folder, we could use the following PHP code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
session_start();&lt;br /&gt;
&lt;br /&gt;
// Get the filename and make sure it is valid&lt;br /&gt;
$filename = basename($_FILES['uploadedfile']['name']);&lt;br /&gt;
if( !preg_match('/^[\w_\.\-]+$/', $filename) ){&lt;br /&gt;
	echo &amp;quot;Invalid filename&amp;quot;;&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Get the username and make sure it is valid&lt;br /&gt;
$username = $_SESSION['username'];&lt;br /&gt;
if( !preg_match('/^[\w_\-]+$/', $username) ){&lt;br /&gt;
	echo &amp;quot;Invalid username&amp;quot;;&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$full_path = sprintf(&amp;quot;/srv/uploads/%s/%s&amp;quot;, $username, $filename);&lt;br /&gt;
&lt;br /&gt;
if( move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $full_path) ){&lt;br /&gt;
	header(&amp;quot;Location: upload_success.html&amp;quot;);&lt;br /&gt;
	exit;&lt;br /&gt;
}else{&lt;br /&gt;
	header(&amp;quot;Location: upload_failure.html&amp;quot;);&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' A lot of the code above is the same as the code in the file download example.  In your project, you should save the logic of generating the file path (in a function) in a third file that you include into the upload and download scripts.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' By default, PHP will not allow a file upload of more than 2 MB.  SitePoint has an excellent tutorial for how to increase this limit: http://www.sitepoint.com/upload-large-files-in-php/&lt;br /&gt;
&lt;br /&gt;
== PEAR ==&lt;br /&gt;
&lt;br /&gt;
The PHP Extension and Application Repository, or '''PEAR''', is a package manager that enables you to install classes and/or extensions to PHP.  In other words, it is a yum/apt for PHP.  You can think of PEAR as PHP's analog of ''gem'' in Ruby or ''pip'' in Python.&lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
PEAR is available through both the yum and apt repositories under the package name '''php-pear'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum install php7-pear  # in RHEL&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Installing PHP Extensions ===&lt;br /&gt;
&lt;br /&gt;
Using PEAR to install PHP extensions is just as easy as yum, apt, gem, and pip.  Just run '''sudo pear install xxx'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo pear install Archive_Tar&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go here for a list of available packages in PEAR: http://pear.php.net/packages.php&lt;br /&gt;
&lt;br /&gt;
=== Using PHP Extensions ===&lt;br /&gt;
&lt;br /&gt;
To make use an extension installed in PEAR, you must '''include''' or '''require''' it into the PHP file of interest.  For example, if you wanted to use the Archive_Tar class from the above example in a PHP file, you would do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
require &amp;quot;Archive/Tar.php&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
// your code here&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By convention, the filepath you need to specify is the name of the PEAR package with underscores replaced with slashes and a .php extension at the end.  For example, the package ''Console_Getargs'' becomes &amp;lt;code&amp;gt;require &amp;quot;Console/Getargs.php&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PECL ===&lt;br /&gt;
&lt;br /&gt;
The PHP Extension Community Library, or '''PECL''', is a repository for additional PHP extensions, the difference being that PECL extensions are written in compiled C code rather than PHP.&lt;br /&gt;
&lt;br /&gt;
PECL is installed automatically when you install PEAR from yum or apt-get.&lt;br /&gt;
&lt;br /&gt;
Installing an extension using PECL is almost identical to PEAR, except that you use '''pecl''' instead of '''pear''' on the command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo pecl install imagick&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You do not need to '''require''' or '''include''' PECL extensions since they are already compiled into PHP.&lt;br /&gt;
&lt;br /&gt;
== PHP Reference ==&lt;br /&gt;
&lt;br /&gt;
If you ever have a question about PHP, first check the well-written documentation.  To skip immediately to the documentation on any function, simply visit &amp;lt;nowiki&amp;gt;http://php.net/&amp;lt;/nowiki&amp;gt;'''functionname'''.  For example: http://php.net/var_dump&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2775</id>
		<title>Amazon Web Services</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2775"/>
		<updated>2021-01-21T21:44:57Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Creating and Configuring your EC2 Instance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Amazon Web Services provides a method to publish web sites on virtual machines in the &amp;quot;cloud.&amp;quot;  In CSE330, you will be using an EC2 instance to host your web site.&lt;br /&gt;
&lt;br /&gt;
Before reading this guide, you should be familiar with Linux and the various distributions of Linux.  Fore more information, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
== Creating and Configuring your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Follow these steps to get to the AWS Management Console:&lt;br /&gt;
&lt;br /&gt;
# Create an AWS account: http://aws.amazon.com/&lt;br /&gt;
# Sign up for the EC2 Web Service: http://aws.amazon.com/ec2/&lt;br /&gt;
# Log in to the AWS Management Console&lt;br /&gt;
&lt;br /&gt;
To create your new virtual machine, click '''Launch Instance'''.  Do the following to configure your instance:&lt;br /&gt;
&lt;br /&gt;
# Choose the image labeled &amp;quot;Amazon Linux 2 AMI&amp;quot;, and make sure you have x86 selected on the right (this should be the default). Please do not choose any other instance image (for example, do NOT choose the macOS images just because you have a Mac), as selecting the wrong image will cause problems later.  For more information on distributions, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
# The default instance variables are all fine.  Click Next until you get to the &amp;quot;Step 6: Configure Security group&amp;quot; screen.&lt;br /&gt;
# Make sure your security group includes a rule of type &amp;quot;SSH&amp;quot;, protocol &amp;quot;TCP&amp;quot;, port range &amp;quot;22&amp;quot;, and source of &amp;quot;0.0.0.0/0&amp;quot; or &amp;quot;Anywhere&amp;quot;. If it does not include an SSH rule, click the &amp;quot;Add Rule&amp;quot; button and set the rule accordingly. The security groups you create determine whether a port is open or blocked for your server.&lt;br /&gt;
#* It might be helpful to change the name for the security group to be more descriptive, such as &amp;quot;CSE330 Instance 1 Security Group&amp;quot; or similar.&lt;br /&gt;
# Click &amp;quot;Review and Launch&amp;quot;, and then &amp;quot;Launch&amp;quot;. Then, in the dialog box, create a new Key Pair.  Enter some name for it, and then click &amp;quot;Create &amp;amp; Download your Key Pair&amp;quot;.  '''Save your key somewhere secure.'''  In addition to using it to authenticate for this instance, you will be able to use the same key for additional instances. Please note that this is needed to connect to the instance as the root user, and there is no way to download this file again. It is vital you do not lose or delete this file.&lt;br /&gt;
# You are now ready to launch your virtual server!  Click &amp;quot;Launch Instances&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Starting and Stopping your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
You can start and stop your instance by right-clicking on the instance.  The options are down in the &amp;quot;Instance Lifecycle&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
=== Amazon EC2 Gives You One Free Micro Instance ===&lt;br /&gt;
&lt;br /&gt;
It is free to keep '''''one''''' micro instance running at all times.  The AWS Free Tier includes 750 hours of Micro instance usage per month for a year; given that the longest month is 744 hours long, the Free Tier is enough to keep a single Micro instance running 24/7 for a year.  Keeping your instance running around the clock will make your life easier, because then you won't need to always change your hostname in your SSH clients.&lt;br /&gt;
&lt;br /&gt;
For additional micro instances, or for larger instances, you will be charged hourly for their use.  One non-free micro instance costs about $14/month; a small instance costs about $43/month.&lt;br /&gt;
&lt;br /&gt;
=== Terminate vs Stop ===&lt;br /&gt;
&lt;br /&gt;
Never &amp;quot;terminate&amp;quot; your instance, as this PERMANENTLY DELETES the instance! Any time you are done using the instance you should instead &amp;quot;stop&amp;quot; the instance and then when you are ready to resume work you should &amp;quot;start&amp;quot; the instance.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Frequently committing your work to your repository is a safety net in case something horrible happens to your instance.&lt;br /&gt;
&lt;br /&gt;
== Enabling Web Access to your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Once you have configured [[Apache]] (which you will do later in this Module), you will need to open up your EC2 instance to web traffic.  (By default amazon blocks all traffic to our instance.)&lt;br /&gt;
&lt;br /&gt;
Go to the Security Groups under Network &amp;amp; Security on the EC2 webpage. Select your security group, click on the Inbound Tab. Add a new Custom TCP rule with a Port range of 80.  Leave the Source at 0.0.0.0/0 (for all traffic). Click Add Rule, and then click Apply Rule Change.&lt;br /&gt;
&lt;br /&gt;
To make sure things are working, create a file, like '''hello.txt''', in your web server root.  Give it some content (might I suggest &amp;quot;Hello, world!&amp;quot;). The web server root is at /var/www/html&lt;br /&gt;
&lt;br /&gt;
For more information on editing files on the command line, refer to [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
You should now be able to visit your server load up the file using your web browser!  Example Link: http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
NOTE:depending on the city in which your server is located, your link might look like:&lt;br /&gt;
&lt;br /&gt;
http://ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2774</id>
		<title>Amazon Web Services</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2774"/>
		<updated>2021-01-14T20:29:53Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Creating and Configuring your EC2 Instance */  Spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Amazon Web Services provides a method to publish web sites on virtual machines in the &amp;quot;cloud.&amp;quot;  In CSE330, you will be using an EC2 instance to host your web site.&lt;br /&gt;
&lt;br /&gt;
Before reading this guide, you should be familiar with Linux and the various distributions of Linux.  Fore more information, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
== Creating and Configuring your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Follow these steps to get to the AWS Management Console:&lt;br /&gt;
&lt;br /&gt;
# Create an AWS account: http://aws.amazon.com/&lt;br /&gt;
# Sign up for the EC2 Web Service: http://aws.amazon.com/ec2/&lt;br /&gt;
# Log in to the AWS Management Console&lt;br /&gt;
&lt;br /&gt;
To create your new virtual machine, click '''Launch Instance'''.  Do the following to configure your instance:&lt;br /&gt;
&lt;br /&gt;
# Choose the image labeled &amp;quot;Amazon Linux AMI 2&amp;quot;, and make sure you have x86 selected on the right (this should be the default). Please do not choose any other instance image (for example, do NOT choose the macOS images just because you have a Mac), as selecting the wrong image will cause problems later.  For more information on distributions, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
# The default instance variables are all fine.  Click Next until you get to the &amp;quot;Step 6: Configure Security group&amp;quot; screen.&lt;br /&gt;
# Make sure your security group includes a rule of type &amp;quot;SSH&amp;quot;, protocol &amp;quot;TCP&amp;quot;, port range &amp;quot;22&amp;quot;, and source of &amp;quot;0.0.0.0/0&amp;quot; or &amp;quot;Anywhere&amp;quot;. If it does not include an SSH rule, click the &amp;quot;Add Rule&amp;quot; button and set the rule accordingly. The security groups you create determine whether a port is open or blocked for your server.&lt;br /&gt;
#* It might be helpful to change the name for the security group to be more descriptive, such as &amp;quot;CSE330 Instance 1 Security Group&amp;quot; or similar.&lt;br /&gt;
# Click &amp;quot;Review and Launch&amp;quot;, and then &amp;quot;Launch&amp;quot;. Then, in the dialog box, create a new Key Pair.  Enter some name for it, and then click &amp;quot;Create &amp;amp; Download your Key Pair&amp;quot;.  '''Save your key somewhere secure.'''  In addition to using it to authenticate for this instance, you will be able to use the same key for additional instances. Please note that this is needed to connect to the instance as the root user, and there is no way to download this file again. It is vital you do not lose or delete this file.&lt;br /&gt;
# You are now ready to launch your virtual server!  Click &amp;quot;Launch Instances&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Starting and Stopping your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
You can start and stop your instance by right-clicking on the instance.  The options are down in the &amp;quot;Instance Lifecycle&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
=== Amazon EC2 Gives You One Free Micro Instance ===&lt;br /&gt;
&lt;br /&gt;
It is free to keep '''''one''''' micro instance running at all times.  The AWS Free Tier includes 750 hours of Micro instance usage per month for a year; given that the longest month is 744 hours long, the Free Tier is enough to keep a single Micro instance running 24/7 for a year.  Keeping your instance running around the clock will make your life easier, because then you won't need to always change your hostname in your SSH clients.&lt;br /&gt;
&lt;br /&gt;
For additional micro instances, or for larger instances, you will be charged hourly for their use.  One non-free micro instance costs about $14/month; a small instance costs about $43/month.&lt;br /&gt;
&lt;br /&gt;
=== Terminate vs Stop ===&lt;br /&gt;
&lt;br /&gt;
Never &amp;quot;terminate&amp;quot; your instance, as this PERMANENTLY DELETES the instance! Any time you are done using the instance you should instead &amp;quot;stop&amp;quot; the instance and then when you are ready to resume work you should &amp;quot;start&amp;quot; the instance.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Frequently committing your work to your repository is a safety net in case something horrible happens to your instance.&lt;br /&gt;
&lt;br /&gt;
== Enabling Web Access to your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Once you have configured [[Apache]] (which you will do later in this Module), you will need to open up your EC2 instance to web traffic.  (By default amazon blocks all traffic to our instance.)&lt;br /&gt;
&lt;br /&gt;
Go to the Security Groups under Network &amp;amp; Security on the EC2 webpage. Select your security group, click on the Inbound Tab. Add a new Custom TCP rule with a Port range of 80.  Leave the Source at 0.0.0.0/0 (for all traffic). Click Add Rule, and then click Apply Rule Change.&lt;br /&gt;
&lt;br /&gt;
To make sure things are working, create a file, like '''hello.txt''', in your web server root.  Give it some content (might I suggest &amp;quot;Hello, world!&amp;quot;). The web server root is at /var/www/html&lt;br /&gt;
&lt;br /&gt;
For more information on editing files on the command line, refer to [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
You should now be able to visit your server load up the file using your web browser!  Example Link: http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
NOTE:depending on the city in which your server is located, your link might look like:&lt;br /&gt;
&lt;br /&gt;
http://ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Apache&amp;diff=2773</id>
		<title>Apache</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Apache&amp;diff=2773"/>
		<updated>2021-01-14T15:40:19Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Installing Apache */  Changed version of Apache to latest as per https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-lamp-amazon-linux-2.html#prepare-lamp-server&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''Apache'' is the industry standard web server for Linux distributions.  It is highly configurable and has a wide range of modules ready for different needs.&lt;br /&gt;
&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=permanence&lt;br /&gt;
|id=910&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== What is a web server? ==&lt;br /&gt;
&lt;br /&gt;
A web server is software that listens for connections to your machine, and when a connection is receive, processes the request and responds with the appropriate information.  Most web servers listen on port 80, which is reserved for the purpose, and use the HTTP protocol.&lt;br /&gt;
&lt;br /&gt;
For example, when you visit this wiki, you are sending a request over the internet to some machine that is probably located somewhere in EIT (the user seldom knows exactly where the machine is located).  The web server receives your request, and it processes the data you sent.  Finally, the server prepares a response (the web page), and sends it back to you.&lt;br /&gt;
&lt;br /&gt;
== Installing Apache ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
In yum, Apache is distributed under the package name '''httpd24''' (for ''hypertext transfer protocol daemon'').  Use the package manager associated with your distribution to install Apache.  (For more information on how to use yum, see [[Linux#Repository-Based Package Managers|the Linux guide]].)&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum update&lt;br /&gt;
$ sudo yum install httpd&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You'll need to run this command to add Apache as a startup item:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo /sbin/chkconfig --levels 235 httpd on&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In RHEL, most Apache configurations are stored in ''/etc/httpd/conf/httpd.conf'' and others are located in the directory ''/etc/httpd/conf.d/''.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Apache Directives ==&lt;br /&gt;
&lt;br /&gt;
You define your settings for Apache using ''directives''.  Some of the directives you will likely encounter include:&lt;br /&gt;
&lt;br /&gt;
* '''DocumentRoot:''' The path to the directory where the top level web files are going to be stored.&lt;br /&gt;
* '''IfModule:'''  The following block would be included if specified module exists.&lt;br /&gt;
* '''User:''' Which user apache2 will run as.&lt;br /&gt;
* '''Group:''' Which group will have group access to default web files.&lt;br /&gt;
* '''AccessFileName:''' The name of the access file (that specifies user names/passwords and other limitations to files/directories).&lt;br /&gt;
* '''ErrorLog:''' Where any errors will be written.&lt;br /&gt;
* '''Include:''' Include some other files.&lt;br /&gt;
* '''LogFormat:''' How to write a log message.&lt;br /&gt;
* '''ErrorDocument:''' Files to display for some HTTP errors (500, 404, 402 etc.).&lt;br /&gt;
* '''Alias:''' Map a directory URL to some other location on your filesystem.  Requires that the ''Alias'' module be loaded.&lt;br /&gt;
&lt;br /&gt;
=== .htaccess Files ===&lt;br /&gt;
&lt;br /&gt;
You can also specify some Apache configurations without delving into the master configuration file.  To do this, put a file named ''.htaccess'' in any directory that Apache is serving.  All directives in it will be interpreted as if they were in a Directory directive in the master configuration file.&lt;br /&gt;
&lt;br /&gt;
'''VERY IMPORTANT:''' The directory containing ''.htaccess'' must not have the '''AllowOverride None''' directive in the master configuration file in order for '''.htaccess''' to be read.&lt;br /&gt;
=== Directory Directive ===&lt;br /&gt;
&lt;br /&gt;
Use the Directory directive to assign other directives to a specific directory.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Directory /var/www/&amp;gt;&lt;br /&gt;
	Options Indexes FollowSymLinks &lt;br /&gt;
	AllowOverride None&lt;br /&gt;
	Order allow,deny&lt;br /&gt;
	allow from all&lt;br /&gt;
	RedirectMatch ^/$ /apache2-default/&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets options for the ''/var/www'' directory.&lt;br /&gt;
# The '''Options''' directive says that:&lt;br /&gt;
## If no index page is present in a directory, display a directory index page instead&lt;br /&gt;
## Apache will follow symbolic links in the directory&lt;br /&gt;
# '''AllowOverride None''' says that ''.htaccess'' files cannot alter the Apache options in this directory and all sub-directories&lt;br /&gt;
# '''Order allow,deny''' and '''Allow from all''' specifies that anybody is allowed to access this server via HTTP.&lt;br /&gt;
&lt;br /&gt;
Note that this directory is actually the root directory of the web server.&lt;br /&gt;
&lt;br /&gt;
== The UserDir Module ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
The UserDir module lets you access files for any user on the server with a ~, e.g., http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/~paul/&lt;br /&gt;
&lt;br /&gt;
This module comes installed, but not activated by default.&lt;br /&gt;
&lt;br /&gt;
=== Enabling UserDir in RHEL ===&lt;br /&gt;
&lt;br /&gt;
If you are using an RHEL-based distribution for your server (like the Amazon AMI), you need to edit the master Apache configuration file.&lt;br /&gt;
&lt;br /&gt;
Open ''/etc/httpd/conf.d/userdir.conf'' in your favorite text editor.  For more information on command-line text editors, refer to [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
Find the line that says&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir disabled&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and change it to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir disabled root&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, find the line that says&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;#UserDir public_html&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and uncomment it; that is, remove the # so that you have&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;UserDir public_html&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells Apache that the directory containing each user's html files is a subdirectory of their home directory called public_html.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Users need to manually create public_html.  It is not created automatically.&lt;br /&gt;
&lt;br /&gt;
You may also need to change the permissions of your user directory and your public_html directory to allow Apache to read and execute inside them.  To do this, run the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo chmod o+x /home/myusername&lt;br /&gt;
$ sudo chmod o+rx /home/myusername/public_html&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, [[#Restarting Apache and Testing|restart Apache]].&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Remapping UserDir ===&lt;br /&gt;
&lt;br /&gt;
If you want to change the name of the UserDir web server root from '''public_html''' to something else like '''.html''', follow these instructions.  (You do not need to do this for the purposes of CSE 330; this serves as a reference.)&lt;br /&gt;
&lt;br /&gt;
# Rename your '''public_html''' to '''.html'''&lt;br /&gt;
#* The &amp;quot;.&amp;quot; in front of the directory name means that the directory is a hidden one.  You will not see it with the normal &amp;quot;ls&amp;quot; command.  Use &amp;quot;ls -a&amp;quot; to see hidden files as well.&lt;br /&gt;
# Edit the UserDir configuration file.&lt;br /&gt;
#* In RHEL, edit the userDir configuration file at ''/etc/httpd/conf.d/userdir.conf''&lt;br /&gt;
# Find the line that reads &amp;lt;code&amp;gt;UserDir public_html&amp;lt;/code&amp;gt; and change it to &amp;lt;code&amp;gt;UserDir .html/&amp;lt;/code&amp;gt;&lt;br /&gt;
# [[#Restarting Apache and Testing|Restart Apache]].&lt;br /&gt;
&lt;br /&gt;
== Apache Logs ==&lt;br /&gt;
&lt;br /&gt;
Apache creates two log files: one for all access attempts to your server, and one for errors.  The locations of these log files are:&lt;br /&gt;
&lt;br /&gt;
* '''Access Log:''' /var/log/httpd/access_log&lt;br /&gt;
* '''Error Log:''' /var/log/httpd/error_log&lt;br /&gt;
&lt;br /&gt;
You might find it helpful to see access and errors appear &amp;quot;live&amp;quot; in your terminal window as they are created.  To do this, you can use the [[Linux#Command Reference|tail -f]] command.  Since the log files have strict permissions, you will need to also use sudo.  Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo tail -f /var/log/httpd/access_log&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Virtual Hosts ==&lt;br /&gt;
&lt;br /&gt;
'''Virtual Hosts''' are used to run multiple Apache web servers from the same machine.  Virtual hosts can listen for connections on different ports and/or different hostnames, serving completely different web sites to each.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost cse330.dyndns.org&amp;gt;&lt;br /&gt;
	ServerAdmin webmaster@localhost&lt;br /&gt;
	ServerName cse330.dyndns.org&lt;br /&gt;
	DocumentRoot /home/www/cse330/&lt;br /&gt;
	ErrorLog /var/log/httpd/error_log&lt;br /&gt;
	LogLevel warn&lt;br /&gt;
	CustomLog /var/log/apache2/access_log combined&lt;br /&gt;
	ServerSignature On&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration enables any requests that use a host name of ''cse330.dyndns.org'' will use ''/home/www/cse330'' as the root document directory.  Make sure that the DocumentRoot directory exists and is readable by the httpd process.  In RHEL, Apache runs as the '''apache''' user.&lt;br /&gt;
&lt;br /&gt;
It is good practice to put raw server configuration files in ''/etc/httpd/sites-available''.  To activate a site, create a symlink from the configuration in ''sites-available'' to a sibling directory called ''sites-enabled''.&lt;br /&gt;
&lt;br /&gt;
== Restarting Apache and Testing ==&lt;br /&gt;
&lt;br /&gt;
Whenever you make changes to the Apache configuration files, you will need to restart Apache for the changes to take effect.  There are several different ways to restart Apache; they all functionally do (almost) the same thing, so choose your favorite:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo /usr/sbin/apachectl restart&lt;br /&gt;
$ sudo apachectl restart    # if /usr/sbin is in your PATH (which it is *not* by default in RHEL)&lt;br /&gt;
$ sudo /etc/init.d/httpd restart&lt;br /&gt;
$ sudo /sbin/service httpd restart&lt;br /&gt;
$ sudo service httpd restart&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're torn for which version is the &amp;quot;best&amp;quot; to use, the commands involving '''apachectl''' (think &amp;quot;Apache Control&amp;quot;) are written by the Apache folks themselves.  This has a couple advantages:&lt;br /&gt;
* They show you errors in the startup process (if there are any)&lt;br /&gt;
* They give you the option to perform a &amp;quot;soft&amp;quot; restart; that is, a restart that allows any pending connections to complete.  To perform a soft restart, use ''graceful'': &amp;lt;code&amp;gt;sudo apachectl graceful&amp;lt;/code&amp;gt;&lt;br /&gt;
In my anecdotal experience, the '''apachectl''' commands are also faster than the '''service''' or '''init.d''' commands.&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working, create a test file in your home directory under public_html, and then point your browser to it: http://ec2-xxx-xx-xx-xxx.compute-1.amazonaws.com/~yourUserName/hello.txt&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2772</id>
		<title>Amazon Web Services</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2772"/>
		<updated>2021-01-14T15:27:34Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: Updated the instructions for creating an instance (changed to Linux AMI 2 and otherwise modernized it), and added more information about the Free Tier to address some common Piazza questions. Sorry about all the noise on this page; hitting enter submits&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Amazon Web Services provides a method to publish web sites on virtual machines in the &amp;quot;cloud.&amp;quot;  In CSE330, you will be using an EC2 instance to host your web site.&lt;br /&gt;
&lt;br /&gt;
Before reading this guide, you should be familiar with Linux and the various distributions of Linux.  Fore more information, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
== Creating and Configuring your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Follow these steps to get to the AWS Management Console:&lt;br /&gt;
&lt;br /&gt;
# Create an AWS account: http://aws.amazon.com/&lt;br /&gt;
# Sign up for the EC2 Web Service: http://aws.amazon.com/ec2/&lt;br /&gt;
# Log in to the AWS Management Console&lt;br /&gt;
&lt;br /&gt;
To create your new virtual machine, click '''Launch Instance'''.  Do the following to configure your instance:&lt;br /&gt;
&lt;br /&gt;
# Choose the instance labeled &amp;quot;Amazon Linux AMI 2&amp;quot;, and make sure you have x86 selected on the right (this should be the default). Please do not choose any other instance image (for example, do NOT choose the macOS images just because you have a Mac), as selection the wrong image will cause problems later.  For more information on distributions, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
# The default instance variables are all fine.  Click Next until you get to the &amp;quot;Step 6: Configure Security group&amp;quot; screen.&lt;br /&gt;
# Make sure your security group includes a rule of type &amp;quot;SSH&amp;quot;, protocol &amp;quot;TCP&amp;quot;, port range &amp;quot;22&amp;quot;, and source of &amp;quot;0.0.0.0/0&amp;quot; or &amp;quot;Anywhere&amp;quot;. If it does not include an SSH rule, click the &amp;quot;Add Rule&amp;quot; button and set the rule accordingly. The security groups you create determine whether a port is open or blocked for your server.&lt;br /&gt;
#* It might be helpful to change the name for the security group to be more descriptive, such as &amp;quot;CSE330 Instance 1 Security Group&amp;quot; or similar.&lt;br /&gt;
# Click &amp;quot;Review and Launch&amp;quot;, and then &amp;quot;Launch&amp;quot;. Then, in the dialog box, create a new Key Pair.  Enter some name for it, and then click &amp;quot;Create &amp;amp; Download your Key Pair&amp;quot;.  '''Save your key somewhere secure.'''  In addition to using it to authenticate for this instance, you will be able to use the same key for additional instances. Please note that this is needed to connect to the instance as the root user, and there is no way to download this file again. It is vital you do not lose or delete this file.&lt;br /&gt;
# You are now ready to launch your virtual server!  Click &amp;quot;Launch Instances&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Starting and Stopping your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
You can start and stop your instance by right-clicking on the instance.  The options are down in the &amp;quot;Instance Lifecycle&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
=== Amazon EC2 Gives You One Free Micro Instance ===&lt;br /&gt;
&lt;br /&gt;
It is free to keep '''''one''''' micro instance running at all times.  The AWS Free Tier includes 750 hours of Micro instance usage per month for a year; given that the longest month is 744 hours long, the Free Tier is enough to keep a single Micro instance running 24/7 for a year.  Keeping your instance running around the clock will make your life easier, because then you won't need to always change your hostname in your SSH clients.&lt;br /&gt;
&lt;br /&gt;
For additional micro instances, or for larger instances, you will be charged hourly for their use.  One non-free micro instance costs about $14/month; a small instance costs about $43/month.&lt;br /&gt;
&lt;br /&gt;
=== Terminate vs Stop ===&lt;br /&gt;
&lt;br /&gt;
Never &amp;quot;terminate&amp;quot; your instance, as this PERMANENTLY DELETES the instance! Any time you are done using the instance you should instead &amp;quot;stop&amp;quot; the instance and then when you are ready to resume work you should &amp;quot;start&amp;quot; the instance.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Frequently committing your work to your repository is a safety net in case something horrible happens to your instance.&lt;br /&gt;
&lt;br /&gt;
== Enabling Web Access to your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Once you have configured [[Apache]] (which you will do later in this Module), you will need to open up your EC2 instance to web traffic.  (By default amazon blocks all traffic to our instance.)&lt;br /&gt;
&lt;br /&gt;
Go to the Security Groups under Network &amp;amp; Security on the EC2 webpage. Select your security group, click on the Inbound Tab. Add a new Custom TCP rule with a Port range of 80.  Leave the Source at 0.0.0.0/0 (for all traffic). Click Add Rule, and then click Apply Rule Change.&lt;br /&gt;
&lt;br /&gt;
To make sure things are working, create a file, like '''hello.txt''', in your web server root.  Give it some content (might I suggest &amp;quot;Hello, world!&amp;quot;). The web server root is at /var/www/html&lt;br /&gt;
&lt;br /&gt;
For more information on editing files on the command line, refer to [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
You should now be able to visit your server load up the file using your web browser!  Example Link: http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
NOTE:depending on the city in which your server is located, your link might look like:&lt;br /&gt;
&lt;br /&gt;
http://ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2771</id>
		<title>Amazon Web Services</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2771"/>
		<updated>2021-01-14T15:03:29Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: Reverted edits by Jasonren (talk) to last revision by Connor&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Amazon Web Services provides a method to publish web sites on virtual machines in the &amp;quot;cloud.&amp;quot;  In CSE330, you will be using an EC2 instance to host your web site.&lt;br /&gt;
&lt;br /&gt;
Before reading this guide, you should be familiar with Linux and the various distributions of Linux.  Fore more information, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
== Creating and Configuring your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Follow these steps to get to the AWS Management Console:&lt;br /&gt;
&lt;br /&gt;
# Create an AWS account: http://aws.amazon.com/&lt;br /&gt;
# Sign up for the EC2 Web Service: http://aws.amazon.com/ec2/&lt;br /&gt;
# Log in to the AWS Management Console&lt;br /&gt;
&lt;br /&gt;
To create your new virtual machine, click '''Launch Instance'''.  Do the following to configure your instance:&lt;br /&gt;
&lt;br /&gt;
# Use the Classic Wizard.&lt;br /&gt;
# Please... Just please choose distribution of Linux labeled &amp;quot;Amazon Linux AMI&amp;quot;. Make sure to double check before selecting, as is the second option and selecting another distribution will cause problems later. For more information on distributions, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
[[File:Correct_instance_type.png|600px|center]]&lt;br /&gt;
# The default instance variables are all fine.  Click Continue until you get to the &amp;quot;Create Key Pair&amp;quot; screen.&lt;br /&gt;
# Create a new Key Pair.  Enter some name for it, and then click &amp;quot;Create &amp;amp; Download your Key Pair&amp;quot;.  '''Save your key somewhere secure.'''  In addition to using it to authenticate for this instance, you will be able to use the same key for additional instances.&lt;br /&gt;
# Create a new Security Group and connect it to your server.  The security groups you create determine whether a port is open or blocked for your server.&lt;br /&gt;
#* You need to open the SSH port on your server.  To do this, select &amp;quot;SSH&amp;quot; from the drop-down box, and then click &amp;quot;Add Rule.&amp;quot;&lt;br /&gt;
#: We will be opening more ports by modifying the security group at a later time.  Click Continue.&lt;br /&gt;
# You are now ready to launch your virtual server!  Click Launch.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Starting and Stopping your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
You can start and stop your instance by right-clicking on the instance.  The options are down in the &amp;quot;Instance Lifecycle&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
=== Amazon EC2 Gives You One Free Micro Instance ===&lt;br /&gt;
&lt;br /&gt;
It is free to keep '''''one''''' micro instance running at all times.  Keeping your instance running around the clock will make your life easier, because then you won't need to always change your hostname in your SSH clients.&lt;br /&gt;
&lt;br /&gt;
For additional Micro instances, or for larger instances, you will be charged hourly for their use.  One non-free Micro instance costs about $14/month; a Small instance costs about $43/month.&lt;br /&gt;
&lt;br /&gt;
=== Terminate vs Stop ===&lt;br /&gt;
&lt;br /&gt;
Never &amp;quot;terminate&amp;quot; your instance, as this PERMANENTLY DELETES the instance! Any time you are done using the instance you should instead &amp;quot;stop&amp;quot; the instance and then when you are ready to resume work you should &amp;quot;start&amp;quot; the instance.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Frequently committing your work to your repository is a safety net in case something horrible happens to your instance.&lt;br /&gt;
&lt;br /&gt;
== Enabling Web Access to your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Once you have configured [[Apache]] (which you will do later in this Module), you will need to open up your EC2 instance to web traffic.  (By default amazon blocks all traffic to our instance.)&lt;br /&gt;
&lt;br /&gt;
Go to the Security Groups under Network &amp;amp; Security on the EC2 webpage. Select your security group, click on the Inbound Tab. Add a new Custom TCP rule with a Port range of 80.  Leave the Source at 0.0.0.0/0 (for all traffic). Click Add Rule, and then click Apply Rule Change.&lt;br /&gt;
&lt;br /&gt;
To make sure things are working, create a file, like '''hello.txt''', in your web server root.  Give it some content (might I suggest &amp;quot;Hello, world!&amp;quot;). The web server root is at /var/www/html&lt;br /&gt;
&lt;br /&gt;
For more information on editing files on the command line, refer to [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
You should now be able to visit your server load up the file using your web browser!  Example Link: http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
NOTE:depending on the city in which your server is located, your link might look like:&lt;br /&gt;
&lt;br /&gt;
http://ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2770</id>
		<title>Amazon Web Services</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Amazon_Web_Services&amp;diff=2770"/>
		<updated>2021-01-14T15:03:16Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: Updated the instructions for creating an instance.Added additional information about the free tier, as these questions tend to pop up on Piazza.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Amazon Web Services provides a method to publish web sites on virtual machines in the &amp;quot;cloud.&amp;quot;  In CSE330, you will be using an EC2 instance to host your web site.&lt;br /&gt;
&lt;br /&gt;
Before reading this guide, you should be familiar with Linux and the various distributions of Linux.  Fore more information, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
== Creating and Configuring your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Follow these steps to get to the AWS Management Console:&lt;br /&gt;
&lt;br /&gt;
# Create an AWS account: http://aws.amazon.com/&lt;br /&gt;
# Sign up for the EC2 Web Service: http://aws.amazon.com/ec2/&lt;br /&gt;
# Log in to the AWS Management Console&lt;br /&gt;
&lt;br /&gt;
To create your new virtual machine, click '''Launch Instance'''.  Do the following to configure your instance:&lt;br /&gt;
&lt;br /&gt;
# Choose  For more information on distributions, refer to [[Linux#Linux Distributions|the Linux guide]].&lt;br /&gt;
[[File:Correct_instance_type.png|600px|center]]&lt;br /&gt;
# The default instance variables are all fine.  Click Continue until you get to the &amp;quot;Create Key Pair&amp;quot; screen.&lt;br /&gt;
# Create a new Key Pair.  Enter some name for it, and then click &amp;quot;Create &amp;amp; Download your Key Pair&amp;quot;.  '''Save your key somewhere secure.'''  In addition to using it to authenticate for this instance, you will be able to use the same key for additional instances.&lt;br /&gt;
# Create a new Security Group and connect it to your server.  The security groups you create determine whether a port is open or blocked for your server.&lt;br /&gt;
#* You need to open the SSH port on your server.  To do this, select &amp;quot;SSH&amp;quot; from the drop-down box, and then click &amp;quot;Add Rule.&amp;quot;&lt;br /&gt;
#: We will be opening more ports by modifying the security group at a later time.  Click Continue.&lt;br /&gt;
# You are now ready to launch your virtual server!  Click Launch.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Starting and Stopping your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
You can start and stop your instance by right-clicking on the instance.  The options are down in the &amp;quot;Instance Lifecycle&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
=== Amazon EC2 Gives You One Free Micro Instance ===&lt;br /&gt;
&lt;br /&gt;
It is free to keep '''''one''''' micro instance running at all times.  The AWS Free Tier includes 750 hours of Micro instance usage per month for a year; given that the longest month is 744 hours long, the Free Tier is enough to keep a single Micro instance running 24/7 for a year. Keeping your instance running around the clock will make your life easier, because then you won't need to always change your hostname in your SSH clients.&lt;br /&gt;
&lt;br /&gt;
For additional Micro instances, or for larger instances, you will be charged hourly for their use.  One non-free Micro instance costs about $14/month; a Small instance costs about $43/month.&lt;br /&gt;
&lt;br /&gt;
=== Terminate vs Stop ===&lt;br /&gt;
&lt;br /&gt;
Never &amp;quot;terminate&amp;quot; your instance, as this PERMANENTLY DELETES the instance! Any time you are done using the instance you should instead &amp;quot;stop&amp;quot; the instance and then when you are ready to resume work you should &amp;quot;start&amp;quot; the instance.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Frequently committing your work to your repository is a safety net in case something horrible happens to your instance.&lt;br /&gt;
&lt;br /&gt;
== Enabling Web Access to your EC2 Instance ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Once you have configured [[Apache]] (which you will do later in this Module), you will need to open up your EC2 instance to web traffic.  (By default amazon blocks all traffic to our instance.)&lt;br /&gt;
&lt;br /&gt;
Go to the Security Groups under Network &amp;amp; Security on the EC2 webpage. Select your security group, click on the Inbound Tab. Add a new Custom TCP rule with a Port range of 80.  Leave the Source at 0.0.0.0/0 (for all traffic). Click Add Rule, and then click Apply Rule Change.&lt;br /&gt;
&lt;br /&gt;
To make sure things are working, create a file, like '''hello.txt''', in your web server root.  Give it some content (might I suggest &amp;quot;Hello, world!&amp;quot;). The web server root is at /var/www/html&lt;br /&gt;
&lt;br /&gt;
For more information on editing files on the command line, refer to [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
You should now be able to visit your server load up the file using your web browser!  Example Link: http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
NOTE:depending on the city in which your server is located, your link might look like:&lt;br /&gt;
&lt;br /&gt;
http://ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/hello.txt&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_4&amp;diff=2769</id>
		<title>Module 4</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_4&amp;diff=2769"/>
		<updated>2021-01-14T14:57:03Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Write some Regular Expressions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In Module 4, you will learn the fundamentals of Python, a popular scripting language, and Regular Expressions, which give you power in text processing.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Python]]&lt;br /&gt;
* [[Regular Expressions]]&lt;br /&gt;
* [[FAQ - Mod 4]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== Learn Python and Regular Expressions ===&lt;br /&gt;
&lt;br /&gt;
Up to this point in CSE 330, you have used only one programming language: PHP.  In Module 4, you will learn a new language: Python.  Before starting this assignment, you should look over the [[Python|online textbook article about Python]].  You should be using version 3 (or greater) of Python. Additionally, you may find it helpful to look over the [[Regular Expressions|online textbook article about Regular Expressions]].&lt;br /&gt;
&lt;br /&gt;
=== Write some Regular Expressions ===&lt;br /&gt;
&lt;br /&gt;
Please write regular expressions that do each the following:&lt;br /&gt;
&lt;br /&gt;
# Match the substring &amp;quot;hello world&amp;quot; in a string.&lt;br /&gt;
# Find all words in an input string that contains three consecutive vowels, regardless of case.&lt;br /&gt;
# Match an input string that is '''entirely''' a flight code, of the format AA####, where '''AA''' is a two-letter uppercase airline code, and '''####''' is a three- or four-digit flight number.&lt;br /&gt;
Examples:&lt;br /&gt;
   Note: text in ''[[red]]'' is matched by the regular expression. Please note that each line is a '''separate''' test input string. For Regex 3, '''six''' separate test cases are given.&lt;br /&gt;
   Regex 1:  Programmers will often write ''[[hello world]]'' as their first project with a programming language.&lt;br /&gt;
   Regex 2:  The ''[[gooey]]'' peanut butter and jelly sandwich was a ''[[beauty]]''.&lt;br /&gt;
   Regex 3:  ''[[AA312]]''&lt;br /&gt;
             ''[[AA1298]]''&lt;br /&gt;
             ''[[NW1234]]''&lt;br /&gt;
             ''[[US443]]''&lt;br /&gt;
             US31344&lt;br /&gt;
             AA123 extratext&lt;br /&gt;
&lt;br /&gt;
            &lt;br /&gt;
&lt;br /&gt;
Save your regexes to text files – one each.&lt;br /&gt;
&lt;br /&gt;
=== Baseball Stats Counter ===&lt;br /&gt;
&lt;br /&gt;
The St. Louis Cardinals are the most legendary baseball team in the national league.  In this exercise, you will be creating a Python script that reads box scores from a file and computes the Cardinals' players' batting averages in a particular season.&lt;br /&gt;
&lt;br /&gt;
==== Tips and Instructions ====&lt;br /&gt;
&lt;br /&gt;
* You should write a Python script file to solve this problem.&lt;br /&gt;
* You should use a regular expression to parse players' names, at-bats, hits, and runs from the input file.&lt;br /&gt;
* You may want to create a class to hold and compute information about each player.&lt;br /&gt;
* Your file should take one command-line argument: the path to an input file.  If no path is given, your program should print a usage message.&lt;br /&gt;
&lt;br /&gt;
==== Input ====&lt;br /&gt;
&lt;br /&gt;
Sample input files may be found here: http://classes.engineering.wustl.edu/cse330/content/cardinals/&lt;br /&gt;
&lt;br /&gt;
The top of the file contains a citation, and what follows is an entire season of Cardinals Baseball box scores.  Each game starts with a title; for example:&lt;br /&gt;
&lt;br /&gt;
 === St.Louis Cardinals vs. Chicago Cubs, 1940-04-19 ===&lt;br /&gt;
&lt;br /&gt;
What follows are the performance of each player in that game.  The format of each line is as follows:&lt;br /&gt;
&lt;br /&gt;
 XXX batted # times with # hits and # runs&lt;br /&gt;
&lt;br /&gt;
where '''XXX''' is the player's name (you may assume that the name is unique), and each '''#''' are integers representing the number of &amp;quot;at bats&amp;quot;, the number of &amp;quot;hits&amp;quot;, and the number of &amp;quot;runs&amp;quot;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Output ====&lt;br /&gt;
&lt;br /&gt;
Your script needs to output all players' batting average across the season.  A player's batting average is that player's total hits divided by that player's total at-bats throughout the entire season.  For example, Johnny Hopp was at bat 149 times in 1940, and he had 41 hits, so his batting average was 0.275.&lt;br /&gt;
&lt;br /&gt;
Each line in the output should have the format:&lt;br /&gt;
&lt;br /&gt;
 XXX: #.###&lt;br /&gt;
&lt;br /&gt;
where '''XXX''' is the player's name, and '''#.###''' is the player's batting average, '''rounded''' (not truncated) to three decimal places.&lt;br /&gt;
&lt;br /&gt;
The players should be sorted by batting average, with the highest batting average on top.  If two players have the exact same batting average (before rounding occurs), the order between those two players is unimportant.&lt;br /&gt;
&lt;br /&gt;
For example, the correct output for the 1940 season is:&lt;br /&gt;
&amp;lt;!-- Jimmy Brown was 0.280 and Ira Hutchinson was 0.125 --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
Pepper Martin: 0.316&lt;br /&gt;
Walker Cooper: 0.316&lt;br /&gt;
Johnny Mize: 0.314&lt;br /&gt;
Ernie Koy: 0.310&lt;br /&gt;
Enos Slaughter: 0.306&lt;br /&gt;
Joe Medwick: 0.304&lt;br /&gt;
Terry Moore: 0.304&lt;br /&gt;
Joe Orengo: 0.286&lt;br /&gt;
Jimmy Brown: 0.280&lt;br /&gt;
Marty Marion: 0.279&lt;br /&gt;
Don Gutteridge: 0.276&lt;br /&gt;
Johnny Hopp: 0.275&lt;br /&gt;
Creepy Crespi: 0.273&lt;br /&gt;
Mickey Owen: 0.265&lt;br /&gt;
Bill DeLancey: 0.250&lt;br /&gt;
Don Padgett: 0.242&lt;br /&gt;
Stu Martin: 0.238&lt;br /&gt;
Eddie Lake: 0.222&lt;br /&gt;
Hal Epps: 0.214&lt;br /&gt;
Lon Warneke: 0.209&lt;br /&gt;
Harry Walker: 0.185&lt;br /&gt;
Max Lanier: 0.179&lt;br /&gt;
Bill McGee: 0.178&lt;br /&gt;
Carl Doyle: 0.174&lt;br /&gt;
Mort Cooper: 0.157&lt;br /&gt;
Clyde Shoun: 0.145&lt;br /&gt;
Carden Gillenwater: 0.130&lt;br /&gt;
Bob Bowman: 0.067&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 50 points total.&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0. ''' &lt;br /&gt;
&lt;br /&gt;
Upload your baseball code and a file with your Regular expressions.&lt;br /&gt;
&lt;br /&gt;
# '''Regular Expressions (15 Points):'''&lt;br /&gt;
#* '''Your regex files should contain your regex (with no delimiters or flags) and nothing else.'''&lt;br /&gt;
#* Regular Expression 1 Correct and saved in a file named &amp;lt;code&amp;gt;regex1.txt&amp;lt;/code&amp;gt; (5 points)&lt;br /&gt;
#* Regular Expression 2 Correct and saved in a file named &amp;lt;code&amp;gt;regex2.txt&amp;lt;/code&amp;gt;(5 points)&lt;br /&gt;
#* Regular Expression 3 Correct and saved in a file named &amp;lt;code&amp;gt;regex3.txt&amp;lt;/code&amp;gt;(5 points)&lt;br /&gt;
# '''Baseball Stats Counter (35 Points):'''&lt;br /&gt;
#* Solution is written entirely in Python and saved in a file named &amp;lt;code&amp;gt;baseball.py&amp;lt;/code&amp;gt; (8 points)&lt;br /&gt;
#*: ''Note: Failing to write your code in Python 3 will result in losing, at a minimum, points for this category.''&lt;br /&gt;
#* Correct usage of one or more regular expressions to parse and extract data from each line of the input file (8 points)&lt;br /&gt;
#*: ''Note: You should not be using &amp;lt;code&amp;gt;str.split&amp;lt;/code&amp;gt; to extract data.''&lt;br /&gt;
#* Script prints a usage message if a command line argument is not present (4 points)&lt;br /&gt;
#*: ''Note: For an example of a usage message, see [https://en.wikipedia.org/wiki/Usage_message#Examples this link.]''&lt;br /&gt;
#* Output is correct for all test cases (15 points)&lt;br /&gt;
#*: ''This includes sorting and rounding.''&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Socket.IO&amp;diff=2730</id>
		<title>Socket.IO</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Socket.IO&amp;diff=2730"/>
		<updated>2020-11-11T20:06:09Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* The Chat Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;AJAX is useful when one-way communication is satisfactory for your web application.  However, what happens when you need two-way communication, like a chat client or multiplayer game?  AJAX isn't the tool for the job.  This is where '''Socket.IO''' comes in.&lt;br /&gt;
&lt;br /&gt;
Built to work natively with Node.JS, Socket.IO enables asynchronous, two-way communication between the server and the client.  This means that the server can send messages to the client without the client having to ask first, as is the case with AJAX.  As you learn Socket.IO, Non-Blocking I/O will become your best friend!&lt;br /&gt;
&lt;br /&gt;
== Installing Socket.IO ==&lt;br /&gt;
&lt;br /&gt;
Before you install Socket.IO, you need to install [[Node.JS]] and NPM, which is often installed automatically when you install Node.JS.&lt;br /&gt;
&lt;br /&gt;
The NPM package manager is different from many of the package managers we've used in that you need to install remote packages for every project in which you use them.  This means that you need to '''cd''' to the working directory in which you want to keep your Node.JS JavaScript file, ''and then'' run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ npm install socket.io --save&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you pass the ''-g'' to ''npm install'', then the package will be installed &amp;quot;globally&amp;quot; on your instance, so all Node.JS projects will be able to use it.  However, this is not recommended for all projects.  [http://blog.nodejs.org/2011/04/06/npm-1-0-link/ Read Node.JS's justification here.]&lt;br /&gt;
&lt;br /&gt;
== Messaging ==&lt;br /&gt;
&lt;br /&gt;
Socket.IO works by having clients send messages to the server and the server send messages to clients.  For example, consider the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Computer A:&lt;br /&gt;
socket.emit(&amp;quot;info&amp;quot;, {&lt;br /&gt;
	&amp;quot;hello&amp;quot;: &amp;quot;world&amp;quot;&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
// Computer B:&lt;br /&gt;
socket.on(&amp;quot;info&amp;quot;, function (data) {&lt;br /&gt;
	console.log(data.hello);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Computer A could be ''either the client or the server'', and Computer B would be the other.  When '''socket.emit(name, data)''' is called on either end, the callback function in '''socket.on''' that listens for the message named ''name'' is called with the ''data'' from '''socket.emit'''.&lt;br /&gt;
&lt;br /&gt;
== A First Socket.IO Application: Chat Server and Client ==&lt;br /&gt;
&lt;br /&gt;
Building a chat client is surprising simple using Socket.IO and Node.JS, and it gives great insight into the workings of Socket.IO.  Take the time to understand how this example works, and ask questions; if you understand this, the group portion will be easy!&lt;br /&gt;
&lt;br /&gt;
=== The Chat Server ===&lt;br /&gt;
&lt;br /&gt;
You can make a file called ''chat-server.js'' with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Require the packages we will use:&lt;br /&gt;
const http = require(&amp;quot;http&amp;quot;),&lt;br /&gt;
    fs = require(&amp;quot;fs&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
const port = 3456;&lt;br /&gt;
const file = &amp;quot;client.html&amp;quot;;&lt;br /&gt;
// Listen for HTTP connections.  This is essentially a miniature static file server that only serves our one file, client.html, on port 3456:&lt;br /&gt;
const server = http.createServer(function (req, res) {&lt;br /&gt;
    // This callback runs when a new connection is made to our HTTP server.&lt;br /&gt;
&lt;br /&gt;
    fs.readFile(file, function (err, data) {&lt;br /&gt;
        // This callback runs when the client.html file has been read from the filesystem.&lt;br /&gt;
&lt;br /&gt;
        if (err) return res.writeHead(500);&lt;br /&gt;
        res.writeHead(200);&lt;br /&gt;
        res.end(data);&lt;br /&gt;
    });&lt;br /&gt;
});&lt;br /&gt;
server.listen(port);&lt;br /&gt;
&lt;br /&gt;
// Import Socket.IO and pass our HTTP server object to it.&lt;br /&gt;
const socketio = require(&amp;quot;socket.io&amp;quot;)(server, {&lt;br /&gt;
    wsEngine: 'ws'&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
// Attach our Socket.IO server to our HTTP server to listen&lt;br /&gt;
const io = socketio.listen(server);&lt;br /&gt;
io.sockets.on(&amp;quot;connection&amp;quot;, function (socket) {&lt;br /&gt;
    // This callback runs when a new Socket.IO connection is established.&lt;br /&gt;
&lt;br /&gt;
    socket.on('message_to_server', function (data) {&lt;br /&gt;
        // This callback runs when the server receives a new message from the client.&lt;br /&gt;
&lt;br /&gt;
        console.log(&amp;quot;message: &amp;quot; + data[&amp;quot;message&amp;quot;]); // log it to the Node.JS output&lt;br /&gt;
        io.sockets.emit(&amp;quot;message_to_client&amp;quot;, { message: data[&amp;quot;message&amp;quot;] }) // broadcast the message to other users&lt;br /&gt;
    });&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code makes a simple HTTP server that responds to all connections with the contents of the file &amp;quot;client.html&amp;quot;, which we will make in the next step.  We tell Socket.IO to listen for &amp;quot;message&amp;quot; events, and when it hears one, it should emit a new event called &amp;quot;someone said&amp;quot; back to the connected clients.&lt;br /&gt;
&lt;br /&gt;
=== The Chat Client ===&lt;br /&gt;
&lt;br /&gt;
Here is a front-end client that could work with our server, in ''client.html'':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
   &amp;lt;head&amp;gt;&lt;br /&gt;
      &amp;lt;script src=&amp;quot;/socket.io/socket.io.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
      &amp;lt;script type =&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      var socketio = io.connect();&lt;br /&gt;
      socketio.on(&amp;quot;message_to_client&amp;quot;,function(data) {&lt;br /&gt;
         //Append an HR thematic break and the escaped HTML of the new message&lt;br /&gt;
         document.getElementById(&amp;quot;chatlog&amp;quot;).appendChild(document.createElement(&amp;quot;hr&amp;quot;));&lt;br /&gt;
         document.getElementById(&amp;quot;chatlog&amp;quot;).appendChild(document.createTextNode(data['message']));&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
      function sendMessage(){&lt;br /&gt;
         var msg = document.getElementById(&amp;quot;message_input&amp;quot;).value;&lt;br /&gt;
         socketio.emit(&amp;quot;message_to_server&amp;quot;, {message:msg});&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      &amp;lt;/script&amp;gt;&lt;br /&gt;
   &amp;lt;/head&amp;gt;&lt;br /&gt;
   &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;input type=text&amp;quot; id=&amp;quot;message_input&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;button onclick=&amp;quot;sendMessage()&amp;quot;&amp;gt;send&amp;lt;/button&amp;gt;&lt;br /&gt;
      &amp;lt;div id=&amp;quot;chatlog&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This example passes strings as the event data, but you can pass any JavaScript datatype, including object literals.&lt;br /&gt;
&lt;br /&gt;
To see this in action, save these two files in the same directory, cd over to the directory, and start the server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ node chat-server.js&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fire up your favorite browser and navigate to http://localhost:3456/.  Open the page in two windows.  Violà: you have your (very basic) chat client!&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The [http://socket.io/ Socket.IO web site] has concise examples that tell you pretty much all you need to know in order to build a functional Socket.IO web application.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 7]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Socket.IO&amp;diff=2729</id>
		<title>Socket.IO</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Socket.IO&amp;diff=2729"/>
		<updated>2020-11-08T23:12:35Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* The Chat Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;AJAX is useful when one-way communication is satisfactory for your web application.  However, what happens when you need two-way communication, like a chat client or multiplayer game?  AJAX isn't the tool for the job.  This is where '''Socket.IO''' comes in.&lt;br /&gt;
&lt;br /&gt;
Built to work natively with Node.JS, Socket.IO enables asynchronous, two-way communication between the server and the client.  This means that the server can send messages to the client without the client having to ask first, as is the case with AJAX.  As you learn Socket.IO, Non-Blocking I/O will become your best friend!&lt;br /&gt;
&lt;br /&gt;
== Installing Socket.IO ==&lt;br /&gt;
&lt;br /&gt;
Before you install Socket.IO, you need to install [[Node.JS]] and NPM, which is often installed automatically when you install Node.JS.&lt;br /&gt;
&lt;br /&gt;
The NPM package manager is different from many of the package managers we've used in that you need to install remote packages for every project in which you use them.  This means that you need to '''cd''' to the working directory in which you want to keep your Node.JS JavaScript file, ''and then'' run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ npm install socket.io --save&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you pass the ''-g'' to ''npm install'', then the package will be installed &amp;quot;globally&amp;quot; on your instance, so all Node.JS projects will be able to use it.  However, this is not recommended for all projects.  [http://blog.nodejs.org/2011/04/06/npm-1-0-link/ Read Node.JS's justification here.]&lt;br /&gt;
&lt;br /&gt;
== Messaging ==&lt;br /&gt;
&lt;br /&gt;
Socket.IO works by having clients send messages to the server and the server send messages to clients.  For example, consider the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Computer A:&lt;br /&gt;
socket.emit(&amp;quot;info&amp;quot;, {&lt;br /&gt;
	&amp;quot;hello&amp;quot;: &amp;quot;world&amp;quot;&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
// Computer B:&lt;br /&gt;
socket.on(&amp;quot;info&amp;quot;, function (data) {&lt;br /&gt;
	console.log(data.hello);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Computer A could be ''either the client or the server'', and Computer B would be the other.  When '''socket.emit(name, data)''' is called on either end, the callback function in '''socket.on''' that listens for the message named ''name'' is called with the ''data'' from '''socket.emit'''.&lt;br /&gt;
&lt;br /&gt;
== A First Socket.IO Application: Chat Server and Client ==&lt;br /&gt;
&lt;br /&gt;
Building a chat client is surprising simple using Socket.IO and Node.JS, and it gives great insight into the workings of Socket.IO.  Take the time to understand how this example works, and ask questions; if you understand this, the group portion will be easy!&lt;br /&gt;
&lt;br /&gt;
=== The Chat Server ===&lt;br /&gt;
&lt;br /&gt;
You can make a file called ''chat-server.js'' with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Require the packages we will use:&lt;br /&gt;
const http = require(&amp;quot;http&amp;quot;),&lt;br /&gt;
    fs = require(&amp;quot;fs&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
const port = 3456;&lt;br /&gt;
const file = &amp;quot;client.html&amp;quot;;&lt;br /&gt;
// Listen for HTTP connections.  This is essentially a miniature static file server that only serves our one file, client.html, on port 3456:&lt;br /&gt;
const server = http.createServer(function (req, res) {&lt;br /&gt;
    // This callback runs when a new connection is made to our HTTP server.&lt;br /&gt;
&lt;br /&gt;
    fs.readFile(file, function (err, data) {&lt;br /&gt;
        // This callback runs when the client.html file has been read from the filesystem.&lt;br /&gt;
&lt;br /&gt;
        if (err) return res.writeHead(500);&lt;br /&gt;
        res.writeHead(200);&lt;br /&gt;
        res.end(data);&lt;br /&gt;
    });&lt;br /&gt;
});&lt;br /&gt;
server.listen(port);&lt;br /&gt;
&lt;br /&gt;
// Import Socket.IO and pass our HTTP server object to it.&lt;br /&gt;
const socketio = require(&amp;quot;socket.io&amp;quot;)(server);&lt;br /&gt;
&lt;br /&gt;
// Attach our Socket.IO server to our HTTP server to listen&lt;br /&gt;
const io = socketio.listen(server);&lt;br /&gt;
io.sockets.on(&amp;quot;connection&amp;quot;, function (socket) {&lt;br /&gt;
    // This callback runs when a new Socket.IO connection is established.&lt;br /&gt;
&lt;br /&gt;
    socket.on('message_to_server', function (data) {&lt;br /&gt;
        // This callback runs when the server receives a new message from the client.&lt;br /&gt;
&lt;br /&gt;
        console.log(&amp;quot;message: &amp;quot; + data[&amp;quot;message&amp;quot;]); // log it to the Node.JS output&lt;br /&gt;
        io.sockets.emit(&amp;quot;message_to_client&amp;quot;, { message: data[&amp;quot;message&amp;quot;] }) // broadcast the message to other users&lt;br /&gt;
    });&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code makes a simple HTTP server that responds to all connections with the contents of the file &amp;quot;client.html&amp;quot;, which we will make in the next step.  We tell Socket.IO to listen for &amp;quot;message&amp;quot; events, and when it hears one, it should emit a new event called &amp;quot;someone said&amp;quot; back to the connected clients.&lt;br /&gt;
&lt;br /&gt;
=== The Chat Client ===&lt;br /&gt;
&lt;br /&gt;
Here is a front-end client that could work with our server, in ''client.html'':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
   &amp;lt;head&amp;gt;&lt;br /&gt;
      &amp;lt;script src=&amp;quot;/socket.io/socket.io.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
      &amp;lt;script type =&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      var socketio = io.connect();&lt;br /&gt;
      socketio.on(&amp;quot;message_to_client&amp;quot;,function(data) {&lt;br /&gt;
         //Append an HR thematic break and the escaped HTML of the new message&lt;br /&gt;
         document.getElementById(&amp;quot;chatlog&amp;quot;).appendChild(document.createElement(&amp;quot;hr&amp;quot;));&lt;br /&gt;
         document.getElementById(&amp;quot;chatlog&amp;quot;).appendChild(document.createTextNode(data['message']));&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
      function sendMessage(){&lt;br /&gt;
         var msg = document.getElementById(&amp;quot;message_input&amp;quot;).value;&lt;br /&gt;
         socketio.emit(&amp;quot;message_to_server&amp;quot;, {message:msg});&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      &amp;lt;/script&amp;gt;&lt;br /&gt;
   &amp;lt;/head&amp;gt;&lt;br /&gt;
   &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;input type=text&amp;quot; id=&amp;quot;message_input&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;button onclick=&amp;quot;sendMessage()&amp;quot;&amp;gt;send&amp;lt;/button&amp;gt;&lt;br /&gt;
      &amp;lt;div id=&amp;quot;chatlog&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This example passes strings as the event data, but you can pass any JavaScript datatype, including object literals.&lt;br /&gt;
&lt;br /&gt;
To see this in action, save these two files in the same directory, cd over to the directory, and start the server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ node chat-server.js&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fire up your favorite browser and navigate to http://localhost:3456/.  Open the page in two windows.  Violà: you have your (very basic) chat client!&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The [http://socket.io/ Socket.IO web site] has concise examples that tell you pretty much all you need to know in order to build a functional Socket.IO web application.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 7]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Socket.IO&amp;diff=2728</id>
		<title>Socket.IO</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Socket.IO&amp;diff=2728"/>
		<updated>2020-11-08T18:25:02Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* The Chat Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;AJAX is useful when one-way communication is satisfactory for your web application.  However, what happens when you need two-way communication, like a chat client or multiplayer game?  AJAX isn't the tool for the job.  This is where '''Socket.IO''' comes in.&lt;br /&gt;
&lt;br /&gt;
Built to work natively with Node.JS, Socket.IO enables asynchronous, two-way communication between the server and the client.  This means that the server can send messages to the client without the client having to ask first, as is the case with AJAX.  As you learn Socket.IO, Non-Blocking I/O will become your best friend!&lt;br /&gt;
&lt;br /&gt;
== Installing Socket.IO ==&lt;br /&gt;
&lt;br /&gt;
Before you install Socket.IO, you need to install [[Node.JS]] and NPM, which is often installed automatically when you install Node.JS.&lt;br /&gt;
&lt;br /&gt;
The NPM package manager is different from many of the package managers we've used in that you need to install remote packages for every project in which you use them.  This means that you need to '''cd''' to the working directory in which you want to keep your Node.JS JavaScript file, ''and then'' run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ npm install socket.io --save&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you pass the ''-g'' to ''npm install'', then the package will be installed &amp;quot;globally&amp;quot; on your instance, so all Node.JS projects will be able to use it.  However, this is not recommended for all projects.  [http://blog.nodejs.org/2011/04/06/npm-1-0-link/ Read Node.JS's justification here.]&lt;br /&gt;
&lt;br /&gt;
== Messaging ==&lt;br /&gt;
&lt;br /&gt;
Socket.IO works by having clients send messages to the server and the server send messages to clients.  For example, consider the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Computer A:&lt;br /&gt;
socket.emit(&amp;quot;info&amp;quot;, {&lt;br /&gt;
	&amp;quot;hello&amp;quot;: &amp;quot;world&amp;quot;&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
// Computer B:&lt;br /&gt;
socket.on(&amp;quot;info&amp;quot;, function (data) {&lt;br /&gt;
	console.log(data.hello);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Computer A could be ''either the client or the server'', and Computer B would be the other.  When '''socket.emit(name, data)''' is called on either end, the callback function in '''socket.on''' that listens for the message named ''name'' is called with the ''data'' from '''socket.emit'''.&lt;br /&gt;
&lt;br /&gt;
== A First Socket.IO Application: Chat Server and Client ==&lt;br /&gt;
&lt;br /&gt;
Building a chat client is surprising simple using Socket.IO and Node.JS, and it gives great insight into the workings of Socket.IO.  Take the time to understand how this example works, and ask questions; if you understand this, the group portion will be easy!&lt;br /&gt;
&lt;br /&gt;
=== The Chat Server ===&lt;br /&gt;
&lt;br /&gt;
You can make a file called ''chat-server.js'' with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Require the packages we will use:&lt;br /&gt;
const http = require(&amp;quot;http&amp;quot;),&lt;br /&gt;
    fs = require(&amp;quot;fs&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
const port = 3456;&lt;br /&gt;
const file = &amp;quot;client.html&amp;quot;;&lt;br /&gt;
// Listen for HTTP connections.  This is essentially a miniature static file server that only serves our one file, client.html, on port 3456:&lt;br /&gt;
const server = http.createServer(function (req, res) {&lt;br /&gt;
    // This callback runs when a new connection is made to our HTTP server.&lt;br /&gt;
&lt;br /&gt;
    fs.readFile(file, function (err, data) {&lt;br /&gt;
        // This callback runs when the client.html file has been read from the filesystem.&lt;br /&gt;
&lt;br /&gt;
        if (err) return resp.writeHead(500);&lt;br /&gt;
        res.writeHead(200);&lt;br /&gt;
        res.end(data);&lt;br /&gt;
    });&lt;br /&gt;
});&lt;br /&gt;
server.listen(port);&lt;br /&gt;
&lt;br /&gt;
// Import Socket.IO and pass our HTTP server object to it.&lt;br /&gt;
const socketio = require(&amp;quot;socket.io&amp;quot;)(server);&lt;br /&gt;
&lt;br /&gt;
// Attach our Socket.IO server to our HTTP server to listen&lt;br /&gt;
const io = socketio.listen(server);&lt;br /&gt;
io.sockets.on(&amp;quot;connection&amp;quot;, function (socket) {&lt;br /&gt;
    // This callback runs when a new Socket.IO connection is established.&lt;br /&gt;
&lt;br /&gt;
    socket.on('message_to_server', function (data) {&lt;br /&gt;
        // This callback runs when the server receives a new message from the client.&lt;br /&gt;
&lt;br /&gt;
        console.log(&amp;quot;message: &amp;quot; + data[&amp;quot;message&amp;quot;]); // log it to the Node.JS output&lt;br /&gt;
        io.sockets.emit(&amp;quot;message_to_client&amp;quot;, { message: data[&amp;quot;message&amp;quot;] }) // broadcast the message to other users&lt;br /&gt;
    });&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code makes a simple HTTP server that responds to all connections with the contents of the file &amp;quot;client.html&amp;quot;, which we will make in the next step.  We tell Socket.IO to listen for &amp;quot;message&amp;quot; events, and when it hears one, it should emit a new event called &amp;quot;someone said&amp;quot; back to the connected clients.&lt;br /&gt;
&lt;br /&gt;
=== The Chat Client ===&lt;br /&gt;
&lt;br /&gt;
Here is a front-end client that could work with our server, in ''client.html'':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
   &amp;lt;head&amp;gt;&lt;br /&gt;
      &amp;lt;script src=&amp;quot;/socket.io/socket.io.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
      &amp;lt;script type =&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      var socketio = io.connect();&lt;br /&gt;
      socketio.on(&amp;quot;message_to_client&amp;quot;,function(data) {&lt;br /&gt;
         //Append an HR thematic break and the escaped HTML of the new message&lt;br /&gt;
         document.getElementById(&amp;quot;chatlog&amp;quot;).appendChild(document.createElement(&amp;quot;hr&amp;quot;));&lt;br /&gt;
         document.getElementById(&amp;quot;chatlog&amp;quot;).appendChild(document.createTextNode(data['message']));&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
      function sendMessage(){&lt;br /&gt;
         var msg = document.getElementById(&amp;quot;message_input&amp;quot;).value;&lt;br /&gt;
         socketio.emit(&amp;quot;message_to_server&amp;quot;, {message:msg});&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      &amp;lt;/script&amp;gt;&lt;br /&gt;
   &amp;lt;/head&amp;gt;&lt;br /&gt;
   &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;input type=text&amp;quot; id=&amp;quot;message_input&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;button onclick=&amp;quot;sendMessage()&amp;quot;&amp;gt;send&amp;lt;/button&amp;gt;&lt;br /&gt;
      &amp;lt;div id=&amp;quot;chatlog&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This example passes strings as the event data, but you can pass any JavaScript datatype, including object literals.&lt;br /&gt;
&lt;br /&gt;
To see this in action, save these two files in the same directory, cd over to the directory, and start the server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ node chat-server.js&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fire up your favorite browser and navigate to http://localhost:3456/.  Open the page in two windows.  Violà: you have your (very basic) chat client!&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The [http://socket.io/ Socket.IO web site] has concise examples that tell you pretty much all you need to know in order to build a functional Socket.IO web application.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 7]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2727</id>
		<title>VS Code</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2727"/>
		<updated>2020-09-18T20:08:55Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* DISCLAIMER */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Getting Started With Each Module ==&lt;br /&gt;
&lt;br /&gt;
* Create Github repo using the CSE 330 repo creator  (Check Piazza for the link)&lt;br /&gt;
* Navigate to the created repo in Github&lt;br /&gt;
* Clone the repo via https to a dedicated folder on your computer&lt;br /&gt;
&lt;br /&gt;
[[File:File-Structure.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* In VS Code, File &amp;gt; Open the Spring2019-module1-individual-STUDENTID '''folder''' that you cloned to your computer&lt;br /&gt;
&lt;br /&gt;
If you followed the above steps correctly, the folder's Git should be configured to your Github repository!  I highly recommend creating your Github repo, cloning the folder to a designated spot, and keeping all modules separated for the semester as shown in the image above.&lt;br /&gt;
&lt;br /&gt;
== Module 1 -- Using the Git Integration ==&lt;br /&gt;
'''Note: If you're using Windows, you may need to install Git on your machine first. https://git-scm.com/download/win . You can check if you have Git running by typing git --version in your terminal'''&lt;br /&gt;
&lt;br /&gt;
* First, open the File Explorer tab on the left, and right click to create a new file, birthday.html&lt;br /&gt;
[[File:New-file.png|400px|center]]&lt;br /&gt;
* Ensure VS Code has it marked as an html file (see the file type next to the smiley face)&lt;br /&gt;
* Type '''doc''' followed by enter, and allow VS Code to generate a basic HTML file for you (use VS Code to your advantage! It can do a lot of your coding for you).&lt;br /&gt;
* Save the file, you should see a popup next to the Version Control symbol on the left. VS Code has detected that your project is different than what it is in your remote Github repo.&lt;br /&gt;
* To commit, simply type a message in the box and click the check mark above it.  To push to your Github repo, click the 3 dots next to the check mark and select 'push'&lt;br /&gt;
* Note this is also where you can pull from your remote.&lt;br /&gt;
&lt;br /&gt;
==== Bonus - Module 1 ====&lt;br /&gt;
* If you like your text editor to look pretty, you can go to the Extensions tab and search for different themes. (Check out the Material theme!)&lt;br /&gt;
* You can view your settings by clicking CMD + , (Mac) or Ctrl + , (Windows).  Search for Theme and choose one that works for you!&lt;br /&gt;
&lt;br /&gt;
== Module 2 == &lt;br /&gt;
=== DISCLAIMER ===&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;The following instructions rely on a third-party VSCode plug-in that is not actively maintained. As of 9/18/2020, the last commit in that repository is over a year ago. '''Use at your own risk!''' There are several reports that this plug-in has issues with private key authentication on versions of VSCode later than 1.35.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== SFTP Integration (Shipping files to your server) ===&lt;br /&gt;
# Open the Extensions tab and search for 'sftp'. Download the first one.&lt;br /&gt;
# To use commands in VS Code, type '''Cmd + Shift + P''' (Mac), or '''Ctrl + Shift + P''' on windows. &lt;br /&gt;
# Type SFTP and open the sftp config command. &lt;br /&gt;
&lt;br /&gt;
Your config.json file should look like the following:&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;YOUR.EC2.DNS&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;YOUR USERNAME&amp;quot;,&lt;br /&gt;
    &amp;quot;privateKeyPath&amp;quot;: &amp;quot;/path/to/your/id_rsa&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/home/YOUR USERNAME/public_html/module2&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
- Note the uploadOnSave field is optional, but can be nice!&lt;br /&gt;
- Check the VS Code output for errors in your config.&lt;br /&gt;
&lt;br /&gt;
Additionally: You should notice an SFTP tab on the side of VS Code. Here, you can view the file structure on your server.&lt;br /&gt;
&lt;br /&gt;
=== Testing Everything Locally ===&lt;br /&gt;
If you would like to avoid having to frequently upload your changes to your instance in order to test your changes, you can optionally set up a local PHP server.&lt;br /&gt;
&lt;br /&gt;
'''To run PHP locally'''&lt;br /&gt;
&lt;br /&gt;
'''Windows'''&lt;br /&gt;
# Download WAMP http://www.wampserver.com/en/download-wampserver-64bits/&lt;br /&gt;
# Place your project repositories in Wamp's www/ directory, and navigate to http://localhost in your browser.  You should see your projects listed here, run php files, and use phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
'''Mac'''&lt;br /&gt;
# Download Homebrew. Homebrew is a great package manager for OSx and we will be using it in future modules. &lt;br /&gt;
# Type the following in your terminal and follow instructions&lt;br /&gt;
 /usr/bin/ruby -e &amp;quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;quot;&lt;br /&gt;
# In your terminal, type '''php -v'''. If your version is less than 7, update with brew. '''brew install php'''&lt;br /&gt;
# In VS Code, search for the extension '''Php Server'''. After installing, use VS Code's command pallette with CMD+Shift+P , search for PHP, and select start server.  You should be able to view your project in your localhost&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2726</id>
		<title>VS Code</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2726"/>
		<updated>2020-09-18T20:08:27Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* DISCLAIMER */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Getting Started With Each Module ==&lt;br /&gt;
&lt;br /&gt;
* Create Github repo using the CSE 330 repo creator  (Check Piazza for the link)&lt;br /&gt;
* Navigate to the created repo in Github&lt;br /&gt;
* Clone the repo via https to a dedicated folder on your computer&lt;br /&gt;
&lt;br /&gt;
[[File:File-Structure.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* In VS Code, File &amp;gt; Open the Spring2019-module1-individual-STUDENTID '''folder''' that you cloned to your computer&lt;br /&gt;
&lt;br /&gt;
If you followed the above steps correctly, the folder's Git should be configured to your Github repository!  I highly recommend creating your Github repo, cloning the folder to a designated spot, and keeping all modules separated for the semester as shown in the image above.&lt;br /&gt;
&lt;br /&gt;
== Module 1 -- Using the Git Integration ==&lt;br /&gt;
'''Note: If you're using Windows, you may need to install Git on your machine first. https://git-scm.com/download/win . You can check if you have Git running by typing git --version in your terminal'''&lt;br /&gt;
&lt;br /&gt;
* First, open the File Explorer tab on the left, and right click to create a new file, birthday.html&lt;br /&gt;
[[File:New-file.png|400px|center]]&lt;br /&gt;
* Ensure VS Code has it marked as an html file (see the file type next to the smiley face)&lt;br /&gt;
* Type '''doc''' followed by enter, and allow VS Code to generate a basic HTML file for you (use VS Code to your advantage! It can do a lot of your coding for you).&lt;br /&gt;
* Save the file, you should see a popup next to the Version Control symbol on the left. VS Code has detected that your project is different than what it is in your remote Github repo.&lt;br /&gt;
* To commit, simply type a message in the box and click the check mark above it.  To push to your Github repo, click the 3 dots next to the check mark and select 'push'&lt;br /&gt;
* Note this is also where you can pull from your remote.&lt;br /&gt;
&lt;br /&gt;
==== Bonus - Module 1 ====&lt;br /&gt;
* If you like your text editor to look pretty, you can go to the Extensions tab and search for different themes. (Check out the Material theme!)&lt;br /&gt;
* You can view your settings by clicking CMD + , (Mac) or Ctrl + , (Windows).  Search for Theme and choose one that works for you!&lt;br /&gt;
&lt;br /&gt;
== Module 2 == &lt;br /&gt;
=== DISCLAIMER ===&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;The following instructions rely on a third-party VSCode plug-in that is not actively maintained. As of 9/18/2020, the last commit in that repository is over a year ago. '''Use at your own risk!''' There are several reports that this plug-in no longer works on versions of VSCode later than 1.35.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== SFTP Integration (Shipping files to your server) ===&lt;br /&gt;
# Open the Extensions tab and search for 'sftp'. Download the first one.&lt;br /&gt;
# To use commands in VS Code, type '''Cmd + Shift + P''' (Mac), or '''Ctrl + Shift + P''' on windows. &lt;br /&gt;
# Type SFTP and open the sftp config command. &lt;br /&gt;
&lt;br /&gt;
Your config.json file should look like the following:&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;YOUR.EC2.DNS&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;YOUR USERNAME&amp;quot;,&lt;br /&gt;
    &amp;quot;privateKeyPath&amp;quot;: &amp;quot;/path/to/your/id_rsa&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/home/YOUR USERNAME/public_html/module2&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
- Note the uploadOnSave field is optional, but can be nice!&lt;br /&gt;
- Check the VS Code output for errors in your config.&lt;br /&gt;
&lt;br /&gt;
Additionally: You should notice an SFTP tab on the side of VS Code. Here, you can view the file structure on your server.&lt;br /&gt;
&lt;br /&gt;
=== Testing Everything Locally ===&lt;br /&gt;
If you would like to avoid having to frequently upload your changes to your instance in order to test your changes, you can optionally set up a local PHP server.&lt;br /&gt;
&lt;br /&gt;
'''To run PHP locally'''&lt;br /&gt;
&lt;br /&gt;
'''Windows'''&lt;br /&gt;
# Download WAMP http://www.wampserver.com/en/download-wampserver-64bits/&lt;br /&gt;
# Place your project repositories in Wamp's www/ directory, and navigate to http://localhost in your browser.  You should see your projects listed here, run php files, and use phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
'''Mac'''&lt;br /&gt;
# Download Homebrew. Homebrew is a great package manager for OSx and we will be using it in future modules. &lt;br /&gt;
# Type the following in your terminal and follow instructions&lt;br /&gt;
 /usr/bin/ruby -e &amp;quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;quot;&lt;br /&gt;
# In your terminal, type '''php -v'''. If your version is less than 7, update with brew. '''brew install php'''&lt;br /&gt;
# In VS Code, search for the extension '''Php Server'''. After installing, use VS Code's command pallette with CMD+Shift+P , search for PHP, and select start server.  You should be able to view your project in your localhost&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2725</id>
		<title>Module 2</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2725"/>
		<updated>2020-09-18T19:58:28Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Set Up your Workspace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
Module 2 introduces you to Linux, a command-line environment, the Apache web server, and PHP.  You will create and configure your own cloud instance, install Apache and related software, and then form groups to make a simple file sharing site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;'''DO NOT WAIT UNTIL THE LAST MINUTE TO START ON THIS (or any) MODULE!'''  The most common reason students perform poorly in this class is procrastination.  You have been warned.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Linux]]&lt;br /&gt;
* [[Bash]]&lt;br /&gt;
* [[Amazon Web Services]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Workflow]]&lt;br /&gt;
* [[VS Code]]&lt;br /&gt;
* [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are a lot of wiki pages that you need to read in order to complete the individual portion of Module 2.  The wiki pages contain an assortment of required steps, optional steps, and information.  To make things easier, we have highlighted the ''required steps'' with a red bar, like you see on the left of this message.  Do not skip anything marked with a red bar, or else you will not have a perfectly configured instance.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Learn About Linux ===&lt;br /&gt;
&lt;br /&gt;
Linux is an open-source operating system based on UNIX. Linux is highly versatile and is used in a wide range of applications.&lt;br /&gt;
&lt;br /&gt;
If you are not a Linux guru, read the Linux guide to get started: [[Linux]]&lt;br /&gt;
&lt;br /&gt;
=== Windows Users Only: Enable Windows Subsystem for Linux (WSL) or Install Cygwin ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need WSL or Cygwin in order to log into and configure your EC2 instance. Cygwin is already installed on the CEC machines. If you're using Windows 10, you can use WSL, which is an officially-supported way of accessing a Linux terminal on Windows. If not, you'll have to use Cygwin. Instructions for installing either on your personal machine are located in [[Workflow#Cygwin|the Workflow guide]].&lt;br /&gt;
&lt;br /&gt;
Mac OS X users should located the &amp;quot;Terminal&amp;quot; application, which is installed by default; you will need this in the coming steps.&lt;br /&gt;
&lt;br /&gt;
=== Create an AWS EC2 Instance ===&lt;br /&gt;
&lt;br /&gt;
Once you understand [[Linux]], you need to set up your Amazon EC2 Instance.  Use the AWS article to guide you through the process: [[Amazon Web Services]]&lt;br /&gt;
&lt;br /&gt;
=== Configure SSH ===&lt;br /&gt;
&lt;br /&gt;
Follow the instructions in [[SSH#SSH Configuration|the SSH guide]] to do the following:&lt;br /&gt;
&lt;br /&gt;
# Create your own SSH key pair&lt;br /&gt;
# Log in as the default user to your EC2 instance&lt;br /&gt;
# Create a new user&lt;br /&gt;
# Give the new user your SSH public key&lt;br /&gt;
&lt;br /&gt;
From now on, when you need to log into your EC2 instance as an administrator, just pop up a terminal and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ssh your-username@ec2-xx-xx-xx-xx.compute-1.amazonaws.com&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To save from typing this command in every time you want to access your server, you can set an '''alias''' in your terminal.&lt;br /&gt;
&lt;br /&gt;
In the '''Mac''' terminal, vim ~/.bash_profile and input the following command:&lt;br /&gt;
 $ alias aws='ssh your-username@ec2.xx-xx-xx-xx.compute-1.amazonaws.com'&lt;br /&gt;
Now, whenever you type aws in your terminal, it will type your ssh command.&lt;br /&gt;
&lt;br /&gt;
In '''Cygwin''', vim ~/.bash_profile and input the following:&lt;br /&gt;
 export aws=&amp;quot;ssh your-username@ec2.xx-xx-xx-xx.compute-1.amazonaws.com&amp;quot;&lt;br /&gt;
And you run this command by typing '''$aws'''&lt;br /&gt;
Also note that you may have to restart your terminal for this to take effect, or put the command in your ~/.bashrc file&lt;br /&gt;
&lt;br /&gt;
=== Install Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
Recall that software installation in Linux instances is usually handled through a package manager, like '''yum'''.  For more information, refer to [[Linux#Repository-Based Package Managers|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working properly, '''install your first package(s) according to the ''Essential Packages'' subsection in the Linux guide.'''&lt;br /&gt;
&lt;br /&gt;
=== Set the Timezone ===&lt;br /&gt;
&lt;br /&gt;
'''Set your server to use US Central time (America/Chicago).'''  Instructions are in the Linux guide: [[Linux#Synchronizing Date and Time]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up the Apache Web Server ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install the Apache web server on your EC2 instance'''.  Refer to [[Apache|the Apache guide]].&lt;br /&gt;
&lt;br /&gt;
In order for your web server to be accessible, you need to '''open up Port 80 on your EC2 instance'''.  Instructions are in the AWS guide: [[Amazon Web Services#Enabling Web Access to your EC2 Instance]]&lt;br /&gt;
&lt;br /&gt;
'''Enable the UserDir module in Apache.'''  Instructions are in the Apache guide: [[Apache#The UserDir Module]]&lt;br /&gt;
&lt;br /&gt;
=== Install PHP ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install PHP on your EC2 server'''.  Instructions are at the top of the PHP guide: [[PHP]]&lt;br /&gt;
&lt;br /&gt;
You need to '''configure PHP to show errors'''.  Instructions are immediately below installation in the PHP guide.&lt;br /&gt;
&lt;br /&gt;
=== Learn about the PHP Language ===&lt;br /&gt;
&lt;br /&gt;
Before you can continue, you will need to make yourself acquainted with PHP language components.  Read the PHP guide for an overview: [[PHP#PHP Language Components]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up your Workspace ===&lt;br /&gt;
&lt;br /&gt;
You are now ready to set up the workspace that you will be using for the rest of the semester.  Follow the instructions in [[Workflow]] to:&lt;br /&gt;
&lt;br /&gt;
# Make an account on GitHub&lt;br /&gt;
# Setup a repo using GitHub Classroom&lt;br /&gt;
# Clone your CSE 330 repo from GitHub&lt;br /&gt;
# Install a text editor such as '''VSCode''' to write your assignments with&lt;br /&gt;
# Either install an FTP client, or use SFTP through command line, to transfer files from your local machine to your instance&lt;br /&gt;
&lt;br /&gt;
=== Calculator ===&lt;br /&gt;
&lt;br /&gt;
'''Make a calculator using PHP and an HTML form.'''  The form should have two inputs.  The form should submit a GET request either back to the same page or to a different results page.  The calculator should support addition, subtraction, multiplication, and division by means of a radio button group on the page.  (Consider edge cases!)&lt;br /&gt;
&lt;br /&gt;
=== Git Tutorial ===&lt;br /&gt;
Complete all of the levels of the Main and Remote sections of [https://learngitbranching.js.org/ this Git tutorial]. After you finish the tutorial, take two screenshots showing completion of all of the levels of the Main and Remote sections. Place these two screenshots in your Module 2 Individual repo.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs (that means you and one other person) on this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;In this module, and all future modules, the group portion builds off of material you learn in the individual portion.  You should therefore complete the individual portions prior to working on the group portions.  (Trust us: it will make your life easier!)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple File Sharing Site ===&lt;br /&gt;
&lt;br /&gt;
You will be making a simple file sharing site that supports uploading, viewing, and deleting files associated with various users.  Details:&lt;br /&gt;
&lt;br /&gt;
* You should have a file named '''users.txt''' stored in a secure place on your filesystem.  It should have at least three usernames, with one username per line.&lt;br /&gt;
*: Passwords add an extra layer of complexity (encryption) that we will cover in Module 3.  You will not earn credit for implementing passwords as your creative portion for this module.&lt;br /&gt;
* Users of the file sharing site should be able to enter their username and then log in.&lt;br /&gt;
*: You may implement logins using session variables, or you may implement them using a GET parameter that is passed between pages.  You will need to always use sessions starting in Module 3.&lt;br /&gt;
* Users should see a list of all files associated with their username after the log in.&lt;br /&gt;
* Users should be able to view, upload, and delete files associated with their username.&lt;br /&gt;
* The URI should NOT reveal the internal file structure of your web site.&lt;br /&gt;
** Example of what not to do:  http://www.example.com/download.php?file=/home/paul/file.txt&lt;br /&gt;
** Another bad example:  http://www.example.com/~user/file.txt&lt;br /&gt;
** Good example: http://www.example.com/view.php?user=music&amp;amp;name=file.txt&lt;br /&gt;
*: In general, don't reveal any internal information about the site.&lt;br /&gt;
*: '''Food for thought:''' Given that Apache processes (with the exception of the main process) do not run as root, but rather as the user apache, how can you allow both your user account and the php scripts to read and write the &lt;br /&gt;
*:necessary files?&lt;br /&gt;
*:: ''Hint:'' You shouldn't be storing the user-uploaded files in public_html (that is only the place for your own web-page files), &lt;br /&gt;
*::''Hint number 2:''  you will need to use chown to change permissions to let user apache have permissions on the user-files (that '''are not''' in the public_html folder). If you don't know what this does or how to do this, look at the [[Apache]] page&lt;br /&gt;
* You should customize your file sharing site by implementing an additional feature or two as part of the '''creative portion'''.&lt;br /&gt;
&lt;br /&gt;
You will probably find the PHP guide on this wiki to be helpful: [[PHP#Other PHP Tips]]&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to follow the conventions of FIEO (Filter Input and Escape Output)'''.  Things you should filter include file names, usernames, and so on.&lt;br /&gt;
* '''Your project must pass the W3C Validator with no errors or warnings'''.  For more information, see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 120 points total. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to GitHub by the end of class on the due date. Commit early and often. Failing to commit by the end of class on the due date will result in a 0. &lt;br /&gt;
&lt;br /&gt;
_____________&lt;br /&gt;
&lt;br /&gt;
# '''Cloud Instance and Web Server (30 Points):'''&lt;br /&gt;
#* You can SSH into your instance using your own custom username and SSH key. Put a screenshot in your repository of your terminal SSH-ing into your instance (15 points)&lt;br /&gt;
#* Your custom username is able to perform SUDO commands. Put a screenshot in your repository of you successfully executing a command with sudo (5 points)&lt;br /&gt;
#* The time zone is correct on your instance. Put a screenshot in your repository of the results of the `date` command (5 points)&lt;br /&gt;
#* The UserDir Apache module is working. Place a file in /home/&amp;lt;username&amp;gt;/public_html and link to the file in your README.md (5 points)&lt;br /&gt;
# '''PHP Calculator (15 Points):'''&lt;br /&gt;
#* The calculator is able to perform all four functions with floating point numbers (2 points each, 8 points in total)&lt;br /&gt;
#* Each function is given as a radio button choice (4 points)&lt;br /&gt;
#* The calculator page passes the W3C HTML validator (3 points)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your individual repo with the the link to your calculator.''''' See the Creative Portion section for more information about .md files.&lt;br /&gt;
# '''Git Tutorial (20 Points):'''&lt;br /&gt;
#* Place the two screenshots displaying the completed levels of the Main and Remote sections in your Individual repo&lt;br /&gt;
# '''File Sharing Site (40 Points):'''&lt;br /&gt;
#* '''''File Management (25 Points):'''''&lt;br /&gt;
#** Users should not be able to see any files until they enter a username and log in (4 points)&lt;br /&gt;
#**: ''Remember that users.txt should be stored in a secure location on your filesystem.  That is, '''you should not be able to type any URL into your browser and see the raw users.txt file!'''''&lt;br /&gt;
#** Users can see a list of all files they have uploaded (4 points)&lt;br /&gt;
#** Users can open files they have previously uploaded (5 points)&lt;br /&gt;
#**: ''Note: Users should be able to open not only plain text files but also other file formats: images, spreadsheets, etc.''&lt;br /&gt;
#** Users can upload files (4 points)&lt;br /&gt;
#**: ''Note: Like users.txt, uploaded files should be stored in a secure location on your filesystem.  That is, '''do not keep your uploads directory underneath a directory served by Apache!'''''&lt;br /&gt;
#** Users can delete files.  If a file is &amp;quot;deleted&amp;quot;, it should actually be removed from the filesystem (4 points)&lt;br /&gt;
#** The directory structure is hidden. Users should not be able to access or view files by manipulating a URL. (2 points)&lt;br /&gt;
#** Users can log out (2 points)&lt;br /&gt;
#**: ''Note: If using session variables, you must ''actually'' log out the user by destroying their session; i.e., don't just redirect them to the login screen.''&lt;br /&gt;
#* '''''Best Practices (10 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (4 points)&lt;br /&gt;
#** The site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C validator (3 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** An .md file is a plain text file called a markdown file  [https://guides.github.com/features/mastering-markdown/ ] .  &lt;br /&gt;
#***The contents of your README.md file are shown on your repo, making it easier for us to grade&lt;br /&gt;
#*** You may style the page with bolding, hyperlings, images, block quotes and lists&lt;br /&gt;
#*** [http://dillinger.io/ This online markdown editor] makes it easy to learn this format  &lt;br /&gt;
#** The link to your file sharing site. '''''We need this to grade your work.'''''&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
=== Creative Portion ===&lt;br /&gt;
&lt;br /&gt;
This module and all future modules will require that you invest some time into creating additional features for your group project.  Plan to invest at least 60 minutes of your time into the creative portion.&lt;br /&gt;
&lt;br /&gt;
* The creative portion is an opportunity for you to learn the material of your own interest.&lt;br /&gt;
* You will not earn credit for a creative-portion feature that simply rehashes something you've already done in a previous module.&lt;br /&gt;
&lt;br /&gt;
If you need ideas for a creative portion, or if you want to know whether or not your creative portion idea is &amp;quot;hard enough&amp;quot;, ask a TA.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Workflow&amp;diff=2724</id>
		<title>Workflow</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Workflow&amp;diff=2724"/>
		<updated>2020-09-18T19:54:21Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Github */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The few minutes it takes to optimize your workflow will be the best few minutes you will spend in CSE 330 and your career.  It is remarkable how many hours you can save just by using the best interface for text editing and deployment.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
There are going to be several aspects to our workflow in CSE 330, and we will be switching between multiple different programs.  Here is how they all fit together.&lt;br /&gt;
&lt;br /&gt;
=== Running Commands ===&lt;br /&gt;
&lt;br /&gt;
''Mac OS X:'' You will be running commands on your local machine using '''Terminal''', which you can find in your Applications -&amp;gt; Utilities folder.  You will be connecting to your server via SSH.&lt;br /&gt;
&lt;br /&gt;
''Windows:'' You will be running commands on your local machine using '''WSL''' or '''Cygwin''', which you will install in the next section.  You will be connecting to your server via SSH.&lt;br /&gt;
&lt;br /&gt;
=== Version Control ===&lt;br /&gt;
&lt;br /&gt;
You will be using '''Git''' as your version control system.  Git enables you to keep track of changes to your source code.  If you're using VS Code, the Git integration makes is very user friendly.&lt;br /&gt;
&lt;br /&gt;
=== Text Editing ===&lt;br /&gt;
&lt;br /&gt;
Although we highly recommend '''VS Code''', you may use '''Sublime Text''', '''Komodo Edit''', '''Notepad++''' (for Windows), and '''TextWrangler''' (for Mac). You can also use an IDE, like '''PHPStorm''', if you prefer.&lt;br /&gt;
&lt;br /&gt;
=== File Transfer ===&lt;br /&gt;
&lt;br /&gt;
In order to deploy your projects to your EC2 instance, you need some sort of method to transfer files from your local machine to your instance using SFTP. One option is using '''FileZilla''', an FTP client, to transport files from your local computer to your server.&lt;br /&gt;
&lt;br /&gt;
=== Flowchart ===&lt;br /&gt;
&lt;br /&gt;
If you are more visual, this flowchart might help:&lt;br /&gt;
&lt;br /&gt;
[[File:CSE-330-Workflow.png]]&lt;br /&gt;
&lt;br /&gt;
The flowchart illustrates 3 methods to copy files to your cloud instance: via your text editor, via an external SFTP client, and by cloning your remote Git repository.  We will be primarily using '''Option 2''' in CSE 330 this semester.&lt;br /&gt;
&lt;br /&gt;
In the flowchart, your ''Git Client'' is SourceTree and your ''Text Editor'' is Komodo.  The ''SFTP Client'' could be FileZilla.&lt;br /&gt;
&lt;br /&gt;
== Installing a Terminal Emulator ==&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Windows is based on a fundamentally different architecture than Linux, meaning that, if you want to run Linux programs on Windows, you'll have to enable or install a special terminal emulator for it. Mac users do not need to install a terminal emulator since MacOs itself is a derivative of Unix, which is an ancestor of Linux.  The Terminal utility is all you need.&lt;br /&gt;
&lt;br /&gt;
=== Windows Subsystem for Linux ===&lt;br /&gt;
&lt;br /&gt;
Starting in Windows 10, Windows has the ability to emulate Linux, meaning that you can run Linux commands on Windows, without having to install Cygwin. To enable WSL, follow [https://msdn.microsoft.com/en-us/commandline/wsl/install_guide these instructions]. Once those instructions are complete, you can open a shell by clicking on the Start menu, typing &amp;quot;Bash&amp;quot;, then clicking on the entry labeled &amp;quot;Bash on Ubuntu on Windows&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Cygwin ===&lt;br /&gt;
&lt;br /&gt;
'''Cygwin''' is a Linux Terminal emulator for Windows.&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&lt;br /&gt;
The CEC lab machines already have Cygwin installed.  Follow these instructions to get Cygwin up and running on your personal PC.&lt;br /&gt;
&lt;br /&gt;
# Run ''setup.exe'' from http://www.cygwin.com/&lt;br /&gt;
# Keep the Cygwin directory as the default, ''C:\cygwin''.  Choose a place like ''C:\cygwin\downloads'' to download the installation files.  Choose any download site, although probably one with a .com suffix is best when you're in the US.&lt;br /&gt;
# In the &amp;quot;Select Packages&amp;quot; screen, select the following packages:&lt;br /&gt;
#* Net -&amp;gt; openssh&lt;br /&gt;
#* Net -&amp;gt; openssl&lt;br /&gt;
#* Python -&amp;gt; python3 (you will need this for Module 4)&lt;br /&gt;
#* Devel -&amp;gt; git (version control system)&lt;br /&gt;
#* One or more of the following:&lt;br /&gt;
#** Editors -&amp;gt; vim&lt;br /&gt;
#** Editors -&amp;gt; emacs&lt;br /&gt;
#** Editors -&amp;gt; nano&lt;br /&gt;
# Allow the installation to complete.&lt;br /&gt;
&lt;br /&gt;
Throughout the rest of this course, when we say to &amp;quot;open a terminal&amp;quot;, if you are on Windows, we mean to &amp;quot;open WSL/Cygwin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Github ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
'''Github''' is a service that enables you to store your code for free in the cloud.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Github Account ===&lt;br /&gt;
&lt;br /&gt;
Go to [https://github.org/ Github.org] to create an account.&lt;br /&gt;
&lt;br /&gt;
'''Important:''' Use your @wustl.edu e-mail address to create your account.  This will put your account on the &amp;quot;educational plan&amp;quot;, which removes some limitations of the free account.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Adding Your Key to Github ===&lt;br /&gt;
'''Not uploading your key is perfectly fine, and in many cases easier.  Here are the instructions though, if you'd like'''&lt;br /&gt;
&lt;br /&gt;
# First make sure that you've finished the [[SSH]] guide configuration instructions.&lt;br /&gt;
#: We will use the same key for connecting to your remote server as for connecting to Github.  (This is completely valid practice.)&lt;br /&gt;
# Go to the &amp;quot;SSH keys&amp;quot; section of the settings panel (Manage Account -&amp;gt; SSH Keys)&lt;br /&gt;
# Add a new key.&lt;br /&gt;
#* I recommend naming it after the computer you're using; if you're in the CEC, for example, you could name it &amp;quot;Warehouse Cygwin&amp;quot;.&lt;br /&gt;
#* The contents of your key is the contents of your ''id_rsa.pub''.  It looks like &amp;lt;code&amp;gt;ssh-rsa AAAAB3blahblahblahblah yourname@somedomain&amp;lt;/code&amp;gt;.  It is exactly the same thing that you had to paste into the ''authorized_keys'' file on your EC2 instance.&lt;br /&gt;
&lt;br /&gt;
You will now be able to push code to your Github repository using your personal SSH key.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== FileZilla ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
You can use SFTP from the command line, or you can use any GUI file transfer client.  All FTP clients I have seen also support SFTP.  One popular FTP client is [http://www.filezilla-project.org/ Filezilla].&lt;br /&gt;
&lt;br /&gt;
# Download and install FileZilla from http://filezilla-project.org/download.php?type=client&lt;br /&gt;
#: If you are using a lab computer, you can save it to your H drive.&lt;br /&gt;
# When you launch FileZilla, go to Edit→Settings or FileZilla→Preferences, and go to the SFTP options (under Connection).  Click &amp;quot;Add keyfile…&amp;quot;.&lt;br /&gt;
#* '''Windows users:''' Choose the *.ppk file that you made earlier using Puttygen.&lt;br /&gt;
#* '''Unix users:'''&lt;br /&gt;
#*# Choose your ''id_rsa'' file.   '''OS X Tip:''' Press Shift+Command+Period to reveal hidden files in the file chooser window.&lt;br /&gt;
#*# FileZilla will want to make a *.ppk file.  A good place to save it would be the .ssh directory as ''id_rsa.ppk''.&lt;br /&gt;
#: When finished, press '''OK''' (not the red ×) to save your changes.&lt;br /&gt;
# Back on the main FileZilla screen, there are four fields: Host, Username, Password, and Port.  Fill them in as follows:&lt;br /&gt;
#* '''Hostname:''' sftp://ec2-xxx-xx-xx-xxx.compute-1.amazonaws.com/&lt;br /&gt;
#* '''Username:''' The username you created on your server.&lt;br /&gt;
#* '''Password:''' Since you are using a key, you may leave this blank.&lt;br /&gt;
#*: If you changed your SSH settings to allow password-based authentication, then you could put your password in here.&lt;br /&gt;
#* '''Port:''' 22&lt;br /&gt;
# Then click Quickconnect.  If everything is configured correctly, FileZilla should log into your server.&lt;br /&gt;
&lt;br /&gt;
[[File:FileZilla.png]]&lt;br /&gt;
&lt;br /&gt;
On the left and right of the FileZilla window, you can drag files between your computer and your server.  Thus, you can edit a file in a text editor like Notepad++ on your decktop, and then upload it to your server by simply dragging it from the left pane to the right pane in FileZilla.&lt;br /&gt;
&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2723</id>
		<title>VS Code</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2723"/>
		<updated>2020-09-18T19:48:09Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* Module 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Getting Started With Each Module ==&lt;br /&gt;
&lt;br /&gt;
* Create Github repo using the CSE 330 repo creator  (Check Piazza for the link)&lt;br /&gt;
* Navigate to the created repo in Github&lt;br /&gt;
* Clone the repo via https to a dedicated folder on your computer&lt;br /&gt;
&lt;br /&gt;
[[File:File-Structure.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* In VS Code, File &amp;gt; Open the Spring2019-module1-individual-STUDENTID '''folder''' that you cloned to your computer&lt;br /&gt;
&lt;br /&gt;
If you followed the above steps correctly, the folder's Git should be configured to your Github repository!  I highly recommend creating your Github repo, cloning the folder to a designated spot, and keeping all modules separated for the semester as shown in the image above.&lt;br /&gt;
&lt;br /&gt;
== Module 1 -- Using the Git Integration ==&lt;br /&gt;
'''Note: If you're using Windows, you may need to install Git on your machine first. https://git-scm.com/download/win . You can check if you have Git running by typing git --version in your terminal'''&lt;br /&gt;
&lt;br /&gt;
* First, open the File Explorer tab on the left, and right click to create a new file, birthday.html&lt;br /&gt;
[[File:New-file.png|400px|center]]&lt;br /&gt;
* Ensure VS Code has it marked as an html file (see the file type next to the smiley face)&lt;br /&gt;
* Type '''doc''' followed by enter, and allow VS Code to generate a basic HTML file for you (use VS Code to your advantage! It can do a lot of your coding for you).&lt;br /&gt;
* Save the file, you should see a popup next to the Version Control symbol on the left. VS Code has detected that your project is different than what it is in your remote Github repo.&lt;br /&gt;
* To commit, simply type a message in the box and click the check mark above it.  To push to your Github repo, click the 3 dots next to the check mark and select 'push'&lt;br /&gt;
* Note this is also where you can pull from your remote.&lt;br /&gt;
&lt;br /&gt;
==== Bonus - Module 1 ====&lt;br /&gt;
* If you like your text editor to look pretty, you can go to the Extensions tab and search for different themes. (Check out the Material theme!)&lt;br /&gt;
* You can view your settings by clicking CMD + , (Mac) or Ctrl + , (Windows).  Search for Theme and choose one that works for you!&lt;br /&gt;
&lt;br /&gt;
== Module 2 == &lt;br /&gt;
=== DISCLAIMER ===&lt;br /&gt;
The following instructions rely on a third-party VSCode plug-in that is not actively maintained. As of 9/18/2020, the last commit in that repository is over a year ago. '''Use at your own risk!''' There are several reports that this plug-in no longer works on versions of VSCode later than 1.35.&lt;br /&gt;
&lt;br /&gt;
=== SFTP Integration (Shipping files to your server) ===&lt;br /&gt;
# Open the Extensions tab and search for 'sftp'. Download the first one.&lt;br /&gt;
# To use commands in VS Code, type '''Cmd + Shift + P''' (Mac), or '''Ctrl + Shift + P''' on windows. &lt;br /&gt;
# Type SFTP and open the sftp config command. &lt;br /&gt;
&lt;br /&gt;
Your config.json file should look like the following:&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;YOUR.EC2.DNS&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;YOUR USERNAME&amp;quot;,&lt;br /&gt;
    &amp;quot;privateKeyPath&amp;quot;: &amp;quot;/path/to/your/id_rsa&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/home/YOUR USERNAME/public_html/module2&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
- Note the uploadOnSave field is optional, but can be nice!&lt;br /&gt;
- Check the VS Code output for errors in your config.&lt;br /&gt;
&lt;br /&gt;
Additionally: You should notice an SFTP tab on the side of VS Code. Here, you can view the file structure on your server.&lt;br /&gt;
&lt;br /&gt;
=== Testing Everything Locally ===&lt;br /&gt;
If you would like to avoid having to frequently upload your changes to your instance in order to test your changes, you can optionally set up a local PHP server.&lt;br /&gt;
&lt;br /&gt;
'''To run PHP locally'''&lt;br /&gt;
&lt;br /&gt;
'''Windows'''&lt;br /&gt;
# Download WAMP http://www.wampserver.com/en/download-wampserver-64bits/&lt;br /&gt;
# Place your project repositories in Wamp's www/ directory, and navigate to http://localhost in your browser.  You should see your projects listed here, run php files, and use phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
'''Mac'''&lt;br /&gt;
# Download Homebrew. Homebrew is a great package manager for OSx and we will be using it in future modules. &lt;br /&gt;
# Type the following in your terminal and follow instructions&lt;br /&gt;
 /usr/bin/ruby -e &amp;quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;quot;&lt;br /&gt;
# In your terminal, type '''php -v'''. If your version is less than 7, update with brew. '''brew install php'''&lt;br /&gt;
# In VS Code, search for the extension '''Php Server'''. After installing, use VS Code's command pallette with CMD+Shift+P , search for PHP, and select start server.  You should be able to view your project in your localhost&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Workflow&amp;diff=2722</id>
		<title>Workflow</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Workflow&amp;diff=2722"/>
		<updated>2020-09-18T19:42:18Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* File Transfer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The few minutes it takes to optimize your workflow will be the best few minutes you will spend in CSE 330 and your career.  It is remarkable how many hours you can save just by using the best interface for text editing and deployment.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
There are going to be several aspects to our workflow in CSE 330, and we will be switching between multiple different programs.  Here is how they all fit together.&lt;br /&gt;
&lt;br /&gt;
=== Running Commands ===&lt;br /&gt;
&lt;br /&gt;
''Mac OS X:'' You will be running commands on your local machine using '''Terminal''', which you can find in your Applications -&amp;gt; Utilities folder.  You will be connecting to your server via SSH.&lt;br /&gt;
&lt;br /&gt;
''Windows:'' You will be running commands on your local machine using '''WSL''' or '''Cygwin''', which you will install in the next section.  You will be connecting to your server via SSH.&lt;br /&gt;
&lt;br /&gt;
=== Version Control ===&lt;br /&gt;
&lt;br /&gt;
You will be using '''Git''' as your version control system.  Git enables you to keep track of changes to your source code.  If you're using VS Code, the Git integration makes is very user friendly.&lt;br /&gt;
&lt;br /&gt;
=== Text Editing ===&lt;br /&gt;
&lt;br /&gt;
Although we highly recommend '''VS Code''', you may use '''Sublime Text''', '''Komodo Edit''', '''Notepad++''' (for Windows), and '''TextWrangler''' (for Mac). You can also use an IDE, like '''PHPStorm''', if you prefer.&lt;br /&gt;
&lt;br /&gt;
=== File Transfer ===&lt;br /&gt;
&lt;br /&gt;
In order to deploy your projects to your EC2 instance, you need some sort of method to transfer files from your local machine to your instance using SFTP. One option is using '''FileZilla''', an FTP client, to transport files from your local computer to your server.&lt;br /&gt;
&lt;br /&gt;
=== Flowchart ===&lt;br /&gt;
&lt;br /&gt;
If you are more visual, this flowchart might help:&lt;br /&gt;
&lt;br /&gt;
[[File:CSE-330-Workflow.png]]&lt;br /&gt;
&lt;br /&gt;
The flowchart illustrates 3 methods to copy files to your cloud instance: via your text editor, via an external SFTP client, and by cloning your remote Git repository.  We will be primarily using '''Option 2''' in CSE 330 this semester.&lt;br /&gt;
&lt;br /&gt;
In the flowchart, your ''Git Client'' is SourceTree and your ''Text Editor'' is Komodo.  The ''SFTP Client'' could be FileZilla.&lt;br /&gt;
&lt;br /&gt;
== Installing a Terminal Emulator ==&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Windows is based on a fundamentally different architecture than Linux, meaning that, if you want to run Linux programs on Windows, you'll have to enable or install a special terminal emulator for it. Mac users do not need to install a terminal emulator since MacOs itself is a derivative of Unix, which is an ancestor of Linux.  The Terminal utility is all you need.&lt;br /&gt;
&lt;br /&gt;
=== Windows Subsystem for Linux ===&lt;br /&gt;
&lt;br /&gt;
Starting in Windows 10, Windows has the ability to emulate Linux, meaning that you can run Linux commands on Windows, without having to install Cygwin. To enable WSL, follow [https://msdn.microsoft.com/en-us/commandline/wsl/install_guide these instructions]. Once those instructions are complete, you can open a shell by clicking on the Start menu, typing &amp;quot;Bash&amp;quot;, then clicking on the entry labeled &amp;quot;Bash on Ubuntu on Windows&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Cygwin ===&lt;br /&gt;
&lt;br /&gt;
'''Cygwin''' is a Linux Terminal emulator for Windows.&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&lt;br /&gt;
The CEC lab machines already have Cygwin installed.  Follow these instructions to get Cygwin up and running on your personal PC.&lt;br /&gt;
&lt;br /&gt;
# Run ''setup.exe'' from http://www.cygwin.com/&lt;br /&gt;
# Keep the Cygwin directory as the default, ''C:\cygwin''.  Choose a place like ''C:\cygwin\downloads'' to download the installation files.  Choose any download site, although probably one with a .com suffix is best when you're in the US.&lt;br /&gt;
# In the &amp;quot;Select Packages&amp;quot; screen, select the following packages:&lt;br /&gt;
#* Net -&amp;gt; openssh&lt;br /&gt;
#* Net -&amp;gt; openssl&lt;br /&gt;
#* Python -&amp;gt; python3 (you will need this for Module 4)&lt;br /&gt;
#* Devel -&amp;gt; git (version control system)&lt;br /&gt;
#* One or more of the following:&lt;br /&gt;
#** Editors -&amp;gt; vim&lt;br /&gt;
#** Editors -&amp;gt; emacs&lt;br /&gt;
#** Editors -&amp;gt; nano&lt;br /&gt;
# Allow the installation to complete.&lt;br /&gt;
&lt;br /&gt;
Throughout the rest of this course, when we say to &amp;quot;open a terminal&amp;quot;, if you are on Windows, we mean to &amp;quot;open WSL/Cygwin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Github ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
'''Github''' is a service that enables you to store your code for free in the cloud.  It is similar in spirit to Github, but with a different mission statement.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Github Account ===&lt;br /&gt;
&lt;br /&gt;
Go to [https://github.org/ Github.org] to create an account.&lt;br /&gt;
&lt;br /&gt;
'''Important:''' Use your @wustl.edu e-mail address to create your account.  This will put your account on the &amp;quot;educational plan&amp;quot;, which removes some limitations of the free account.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you know someone who uses Github, you can ask them to invite you as a friend.  This will increase the member limit on the inviter's private repos.&lt;br /&gt;
&lt;br /&gt;
=== Adding Your Key to Github ===&lt;br /&gt;
'''Not uploading your key is perfectly fine, and in many cases easier.  Here are the instructions though, if you'd like'''&lt;br /&gt;
&lt;br /&gt;
# First make sure that you've finished the [[SSH]] guide configuration instructions.&lt;br /&gt;
#: We will use the same key for connecting to your remote server as for connecting to Github.  (This is completely valid practice.)&lt;br /&gt;
# Go to the &amp;quot;SSH keys&amp;quot; section of the settings panel (Manage Account -&amp;gt; SSH Keys)&lt;br /&gt;
# Add a new key.&lt;br /&gt;
#* I recommend naming it after the computer you're using; if you're in the CEC, for example, you could name it &amp;quot;Warehouse Cygwin&amp;quot;.&lt;br /&gt;
#* The contents of your key is the contents of your ''id_rsa.pub''.  It looks like &amp;lt;code&amp;gt;ssh-rsa AAAAB3blahblahblahblah yourname@somedomain&amp;lt;/code&amp;gt;.  It is exactly the same thing that you had to paste into the ''authorized_keys'' file on your EC2 instance.&lt;br /&gt;
&lt;br /&gt;
You will now be able to push code to your Github repository using your personal SSH key.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== FileZilla ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
You can use SFTP from the command line, or you can use any GUI file transfer client.  All FTP clients I have seen also support SFTP.  One popular FTP client is [http://www.filezilla-project.org/ Filezilla].&lt;br /&gt;
&lt;br /&gt;
# Download and install FileZilla from http://filezilla-project.org/download.php?type=client&lt;br /&gt;
#: If you are using a lab computer, you can save it to your H drive.&lt;br /&gt;
# When you launch FileZilla, go to Edit→Settings or FileZilla→Preferences, and go to the SFTP options (under Connection).  Click &amp;quot;Add keyfile…&amp;quot;.&lt;br /&gt;
#* '''Windows users:''' Choose the *.ppk file that you made earlier using Puttygen.&lt;br /&gt;
#* '''Unix users:'''&lt;br /&gt;
#*# Choose your ''id_rsa'' file.   '''OS X Tip:''' Press Shift+Command+Period to reveal hidden files in the file chooser window.&lt;br /&gt;
#*# FileZilla will want to make a *.ppk file.  A good place to save it would be the .ssh directory as ''id_rsa.ppk''.&lt;br /&gt;
#: When finished, press '''OK''' (not the red ×) to save your changes.&lt;br /&gt;
# Back on the main FileZilla screen, there are four fields: Host, Username, Password, and Port.  Fill them in as follows:&lt;br /&gt;
#* '''Hostname:''' sftp://ec2-xxx-xx-xx-xxx.compute-1.amazonaws.com/&lt;br /&gt;
#* '''Username:''' The username you created on your server.&lt;br /&gt;
#* '''Password:''' Since you are using a key, you may leave this blank.&lt;br /&gt;
#*: If you changed your SSH settings to allow password-based authentication, then you could put your password in here.&lt;br /&gt;
#* '''Port:''' 22&lt;br /&gt;
# Then click Quickconnect.  If everything is configured correctly, FileZilla should log into your server.&lt;br /&gt;
&lt;br /&gt;
[[File:FileZilla.png]]&lt;br /&gt;
&lt;br /&gt;
On the left and right of the FileZilla window, you can drag files between your computer and your server.  Thus, you can edit a file in a text editor like Notepad++ on your decktop, and then upload it to your server by simply dragging it from the left pane to the right pane in FileZilla.&lt;br /&gt;
&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Workflow&amp;diff=2721</id>
		<title>Workflow</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Workflow&amp;diff=2721"/>
		<updated>2020-09-18T19:40:02Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: /* FileZilla */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The few minutes it takes to optimize your workflow will be the best few minutes you will spend in CSE 330 and your career.  It is remarkable how many hours you can save just by using the best interface for text editing and deployment.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
There are going to be several aspects to our workflow in CSE 330, and we will be switching between multiple different programs.  Here is how they all fit together.&lt;br /&gt;
&lt;br /&gt;
=== Running Commands ===&lt;br /&gt;
&lt;br /&gt;
''Mac OS X:'' You will be running commands on your local machine using '''Terminal''', which you can find in your Applications -&amp;gt; Utilities folder.  You will be connecting to your server via SSH.&lt;br /&gt;
&lt;br /&gt;
''Windows:'' You will be running commands on your local machine using '''WSL''' or '''Cygwin''', which you will install in the next section.  You will be connecting to your server via SSH.&lt;br /&gt;
&lt;br /&gt;
=== Version Control ===&lt;br /&gt;
&lt;br /&gt;
You will be using '''Git''' as your version control system.  Git enables you to keep track of changes to your source code.  If you're using VS Code, the Git integration makes is very user friendly.&lt;br /&gt;
&lt;br /&gt;
=== Text Editing ===&lt;br /&gt;
&lt;br /&gt;
Although we highly recommend '''VS Code''', you may use '''Sublime Text''', '''Komodo Edit''', '''Notepad++''' (for Windows), and '''TextWrangler''' (for Mac). You can also use an IDE, like '''PHPStorm''', if you prefer.&lt;br /&gt;
&lt;br /&gt;
=== File Transfer ===&lt;br /&gt;
&lt;br /&gt;
See [[VS Code]] and the Module 2 section to see our recommended file transfer method. If you're not using VS Code, you may use '''FileZilla''' to transport files from your local computer to your server.&lt;br /&gt;
&lt;br /&gt;
=== Flowchart ===&lt;br /&gt;
&lt;br /&gt;
If you are more visual, this flowchart might help:&lt;br /&gt;
&lt;br /&gt;
[[File:CSE-330-Workflow.png]]&lt;br /&gt;
&lt;br /&gt;
The flowchart illustrates 3 methods to copy files to your cloud instance: via your text editor, via an external SFTP client, and by cloning your remote Git repository.  We will be primarily using '''Option 2''' in CSE 330 this semester.&lt;br /&gt;
&lt;br /&gt;
In the flowchart, your ''Git Client'' is SourceTree and your ''Text Editor'' is Komodo.  The ''SFTP Client'' could be FileZilla.&lt;br /&gt;
&lt;br /&gt;
== Installing a Terminal Emulator ==&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
Windows is based on a fundamentally different architecture than Linux, meaning that, if you want to run Linux programs on Windows, you'll have to enable or install a special terminal emulator for it. Mac users do not need to install a terminal emulator since MacOs itself is a derivative of Unix, which is an ancestor of Linux.  The Terminal utility is all you need.&lt;br /&gt;
&lt;br /&gt;
=== Windows Subsystem for Linux ===&lt;br /&gt;
&lt;br /&gt;
Starting in Windows 10, Windows has the ability to emulate Linux, meaning that you can run Linux commands on Windows, without having to install Cygwin. To enable WSL, follow [https://msdn.microsoft.com/en-us/commandline/wsl/install_guide these instructions]. Once those instructions are complete, you can open a shell by clicking on the Start menu, typing &amp;quot;Bash&amp;quot;, then clicking on the entry labeled &amp;quot;Bash on Ubuntu on Windows&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Cygwin ===&lt;br /&gt;
&lt;br /&gt;
'''Cygwin''' is a Linux Terminal emulator for Windows.&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&lt;br /&gt;
The CEC lab machines already have Cygwin installed.  Follow these instructions to get Cygwin up and running on your personal PC.&lt;br /&gt;
&lt;br /&gt;
# Run ''setup.exe'' from http://www.cygwin.com/&lt;br /&gt;
# Keep the Cygwin directory as the default, ''C:\cygwin''.  Choose a place like ''C:\cygwin\downloads'' to download the installation files.  Choose any download site, although probably one with a .com suffix is best when you're in the US.&lt;br /&gt;
# In the &amp;quot;Select Packages&amp;quot; screen, select the following packages:&lt;br /&gt;
#* Net -&amp;gt; openssh&lt;br /&gt;
#* Net -&amp;gt; openssl&lt;br /&gt;
#* Python -&amp;gt; python3 (you will need this for Module 4)&lt;br /&gt;
#* Devel -&amp;gt; git (version control system)&lt;br /&gt;
#* One or more of the following:&lt;br /&gt;
#** Editors -&amp;gt; vim&lt;br /&gt;
#** Editors -&amp;gt; emacs&lt;br /&gt;
#** Editors -&amp;gt; nano&lt;br /&gt;
# Allow the installation to complete.&lt;br /&gt;
&lt;br /&gt;
Throughout the rest of this course, when we say to &amp;quot;open a terminal&amp;quot;, if you are on Windows, we mean to &amp;quot;open WSL/Cygwin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Github ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
'''Github''' is a service that enables you to store your code for free in the cloud.  It is similar in spirit to Github, but with a different mission statement.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Github Account ===&lt;br /&gt;
&lt;br /&gt;
Go to [https://github.org/ Github.org] to create an account.&lt;br /&gt;
&lt;br /&gt;
'''Important:''' Use your @wustl.edu e-mail address to create your account.  This will put your account on the &amp;quot;educational plan&amp;quot;, which removes some limitations of the free account.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you know someone who uses Github, you can ask them to invite you as a friend.  This will increase the member limit on the inviter's private repos.&lt;br /&gt;
&lt;br /&gt;
=== Adding Your Key to Github ===&lt;br /&gt;
'''Not uploading your key is perfectly fine, and in many cases easier.  Here are the instructions though, if you'd like'''&lt;br /&gt;
&lt;br /&gt;
# First make sure that you've finished the [[SSH]] guide configuration instructions.&lt;br /&gt;
#: We will use the same key for connecting to your remote server as for connecting to Github.  (This is completely valid practice.)&lt;br /&gt;
# Go to the &amp;quot;SSH keys&amp;quot; section of the settings panel (Manage Account -&amp;gt; SSH Keys)&lt;br /&gt;
# Add a new key.&lt;br /&gt;
#* I recommend naming it after the computer you're using; if you're in the CEC, for example, you could name it &amp;quot;Warehouse Cygwin&amp;quot;.&lt;br /&gt;
#* The contents of your key is the contents of your ''id_rsa.pub''.  It looks like &amp;lt;code&amp;gt;ssh-rsa AAAAB3blahblahblahblah yourname@somedomain&amp;lt;/code&amp;gt;.  It is exactly the same thing that you had to paste into the ''authorized_keys'' file on your EC2 instance.&lt;br /&gt;
&lt;br /&gt;
You will now be able to push code to your Github repository using your personal SSH key.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== FileZilla ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
You can use SFTP from the command line, or you can use any GUI file transfer client.  All FTP clients I have seen also support SFTP.  One popular FTP client is [http://www.filezilla-project.org/ Filezilla].&lt;br /&gt;
&lt;br /&gt;
# Download and install FileZilla from http://filezilla-project.org/download.php?type=client&lt;br /&gt;
#: If you are using a lab computer, you can save it to your H drive.&lt;br /&gt;
# When you launch FileZilla, go to Edit→Settings or FileZilla→Preferences, and go to the SFTP options (under Connection).  Click &amp;quot;Add keyfile…&amp;quot;.&lt;br /&gt;
#* '''Windows users:''' Choose the *.ppk file that you made earlier using Puttygen.&lt;br /&gt;
#* '''Unix users:'''&lt;br /&gt;
#*# Choose your ''id_rsa'' file.   '''OS X Tip:''' Press Shift+Command+Period to reveal hidden files in the file chooser window.&lt;br /&gt;
#*# FileZilla will want to make a *.ppk file.  A good place to save it would be the .ssh directory as ''id_rsa.ppk''.&lt;br /&gt;
#: When finished, press '''OK''' (not the red ×) to save your changes.&lt;br /&gt;
# Back on the main FileZilla screen, there are four fields: Host, Username, Password, and Port.  Fill them in as follows:&lt;br /&gt;
#* '''Hostname:''' sftp://ec2-xxx-xx-xx-xxx.compute-1.amazonaws.com/&lt;br /&gt;
#* '''Username:''' The username you created on your server.&lt;br /&gt;
#* '''Password:''' Since you are using a key, you may leave this blank.&lt;br /&gt;
#*: If you changed your SSH settings to allow password-based authentication, then you could put your password in here.&lt;br /&gt;
#* '''Port:''' 22&lt;br /&gt;
# Then click Quickconnect.  If everything is configured correctly, FileZilla should log into your server.&lt;br /&gt;
&lt;br /&gt;
[[File:FileZilla.png]]&lt;br /&gt;
&lt;br /&gt;
On the left and right of the FileZilla window, you can drag files between your computer and your server.  Thus, you can edit a file in a text editor like Notepad++ on your decktop, and then upload it to your server by simply dragging it from the left pane to the right pane in FileZilla.&lt;br /&gt;
&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2720</id>
		<title>Module 2</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2720"/>
		<updated>2020-09-14T18:23:58Z</updated>

		<summary type="html">&lt;p&gt;Jasonren: Changed rubric to reference new git tutorial&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
Module 2 introduces you to Linux, a command-line environment, the Apache web server, and PHP.  You will create and configure your own cloud instance, install Apache and related software, and then form groups to make a simple file sharing site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;'''DO NOT WAIT UNTIL THE LAST MINUTE TO START ON THIS (or any) MODULE!'''  The most common reason students perform poorly in this class is procrastination.  You have been warned.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Linux]]&lt;br /&gt;
* [[Bash]]&lt;br /&gt;
* [[Amazon Web Services]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Workflow]]&lt;br /&gt;
* [[VS Code]]&lt;br /&gt;
* [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are a lot of wiki pages that you need to read in order to complete the individual portion of Module 2.  The wiki pages contain an assortment of required steps, optional steps, and information.  To make things easier, we have highlighted the ''required steps'' with a red bar, like you see on the left of this message.  Do not skip anything marked with a red bar, or else you will not have a perfectly configured instance.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Learn About Linux ===&lt;br /&gt;
&lt;br /&gt;
Linux is an open-source operating system based on UNIX. Linux is highly versatile and is used in a wide range of applications.&lt;br /&gt;
&lt;br /&gt;
If you are not a Linux guru, read the Linux guide to get started: [[Linux]]&lt;br /&gt;
&lt;br /&gt;
=== Windows Users Only: Enable Windows Subsystem for Linux (WSL) or Install Cygwin ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need WSL or Cygwin in order to log into and configure your EC2 instance. Cygwin is already installed on the CEC machines. If you're using Windows 10, you can use WSL, which is an officially-supported way of accessing a Linux terminal on Windows. If not, you'll have to use Cygwin. Instructions for installing either on your personal machine are located in [[Workflow#Cygwin|the Workflow guide]].&lt;br /&gt;
&lt;br /&gt;
Mac OS X users should located the &amp;quot;Terminal&amp;quot; application, which is installed by default; you will need this in the coming steps.&lt;br /&gt;
&lt;br /&gt;
=== Create an AWS EC2 Instance ===&lt;br /&gt;
&lt;br /&gt;
Once you understand [[Linux]], you need to set up your Amazon EC2 Instance.  Use the AWS article to guide you through the process: [[Amazon Web Services]]&lt;br /&gt;
&lt;br /&gt;
=== Configure SSH ===&lt;br /&gt;
&lt;br /&gt;
Follow the instructions in [[SSH#SSH Configuration|the SSH guide]] to do the following:&lt;br /&gt;
&lt;br /&gt;
# Create your own SSH key pair&lt;br /&gt;
# Log in as the default user to your EC2 instance&lt;br /&gt;
# Create a new user&lt;br /&gt;
# Give the new user your SSH public key&lt;br /&gt;
&lt;br /&gt;
From now on, when you need to log into your EC2 instance as an administrator, just pop up a terminal and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ssh your-username@ec2-xx-xx-xx-xx.compute-1.amazonaws.com&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To save from typing this command in every time you want to access your server, you can set an '''alias''' in your terminal.&lt;br /&gt;
&lt;br /&gt;
In the '''Mac''' terminal, vim ~/.bash_profile and input the following command:&lt;br /&gt;
 $ alias aws='ssh your-username@ec2.xx-xx-xx-xx.compute-1.amazonaws.com'&lt;br /&gt;
Now, whenever you type aws in your terminal, it will type your ssh command.&lt;br /&gt;
&lt;br /&gt;
In '''Cygwin''', vim ~/.bash_profile and input the following:&lt;br /&gt;
 export aws=&amp;quot;ssh your-username@ec2.xx-xx-xx-xx.compute-1.amazonaws.com&amp;quot;&lt;br /&gt;
And you run this command by typing '''$aws'''&lt;br /&gt;
Also note that you may have to restart your terminal for this to take effect, or put the command in your ~/.bashrc file&lt;br /&gt;
&lt;br /&gt;
=== Install Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
Recall that software installation in Linux instances is usually handled through a package manager, like '''yum'''.  For more information, refer to [[Linux#Repository-Based Package Managers|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working properly, '''install your first package(s) according to the ''Essential Packages'' subsection in the Linux guide.'''&lt;br /&gt;
&lt;br /&gt;
=== Set the Timezone ===&lt;br /&gt;
&lt;br /&gt;
'''Set your server to use US Central time (America/Chicago).'''  Instructions are in the Linux guide: [[Linux#Synchronizing Date and Time]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up the Apache Web Server ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install the Apache web server on your EC2 instance'''.  Refer to [[Apache|the Apache guide]].&lt;br /&gt;
&lt;br /&gt;
In order for your web server to be accessible, you need to '''open up Port 80 on your EC2 instance'''.  Instructions are in the AWS guide: [[Amazon Web Services#Enabling Web Access to your EC2 Instance]]&lt;br /&gt;
&lt;br /&gt;
'''Enable the UserDir module in Apache.'''  Instructions are in the Apache guide: [[Apache#The UserDir Module]]&lt;br /&gt;
&lt;br /&gt;
=== Install PHP ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install PHP on your EC2 server'''.  Instructions are at the top of the PHP guide: [[PHP]]&lt;br /&gt;
&lt;br /&gt;
You need to '''configure PHP to show errors'''.  Instructions are immediately below installation in the PHP guide.&lt;br /&gt;
&lt;br /&gt;
=== Learn about the PHP Language ===&lt;br /&gt;
&lt;br /&gt;
Before you can continue, you will need to make yourself acquainted with PHP language components.  Read the PHP guide for an overview: [[PHP#PHP Language Components]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up your Workspace ===&lt;br /&gt;
&lt;br /&gt;
You are now ready to set up the workspace that you will be using for the rest of the semester.  Follow the instructions in [[Workflow]] to:&lt;br /&gt;
&lt;br /&gt;
# Make an account on GitHub&lt;br /&gt;
# Setup a repo using GitHub Classroom&lt;br /&gt;
# Clone your CSE 330 repo from GitHub&lt;br /&gt;
# Follow the SFTP and Git instructions on the [[VS Code]] page&lt;br /&gt;
&lt;br /&gt;
=== Calculator ===&lt;br /&gt;
&lt;br /&gt;
'''Make a calculator using PHP and an HTML form.'''  The form should have two inputs.  The form should submit a GET request either back to the same page or to a different results page.  The calculator should support addition, subtraction, multiplication, and division by means of a radio button group on the page.  (Consider edge cases!)&lt;br /&gt;
&lt;br /&gt;
=== Git Tutorial ===&lt;br /&gt;
Complete all of the levels of the Main and Remote sections of [https://learngitbranching.js.org/ this Git tutorial]. After you finish the tutorial, take two screenshots showing completion of all of the levels of the Main and Remote sections. Place these two screenshots in your Module 2 Individual repo.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs (that means you and one other person) on this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;In this module, and all future modules, the group portion builds off of material you learn in the individual portion.  You should therefore complete the individual portions prior to working on the group portions.  (Trust us: it will make your life easier!)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple File Sharing Site ===&lt;br /&gt;
&lt;br /&gt;
You will be making a simple file sharing site that supports uploading, viewing, and deleting files associated with various users.  Details:&lt;br /&gt;
&lt;br /&gt;
* You should have a file named '''users.txt''' stored in a secure place on your filesystem.  It should have at least three usernames, with one username per line.&lt;br /&gt;
*: Passwords add an extra layer of complexity (encryption) that we will cover in Module 3.  You will not earn credit for implementing passwords as your creative portion for this module.&lt;br /&gt;
* Users of the file sharing site should be able to enter their username and then log in.&lt;br /&gt;
*: You may implement logins using session variables, or you may implement them using a GET parameter that is passed between pages.  You will need to always use sessions starting in Module 3.&lt;br /&gt;
* Users should see a list of all files associated with their username after the log in.&lt;br /&gt;
* Users should be able to view, upload, and delete files associated with their username.&lt;br /&gt;
* The URI should NOT reveal the internal file structure of your web site.&lt;br /&gt;
** Example of what not to do:  http://www.example.com/download.php?file=/home/paul/file.txt&lt;br /&gt;
** Another bad example:  http://www.example.com/~user/file.txt&lt;br /&gt;
** Good example: http://www.example.com/view.php?user=music&amp;amp;name=file.txt&lt;br /&gt;
*: In general, don't reveal any internal information about the site.&lt;br /&gt;
*: '''Food for thought:''' Given that Apache processes (with the exception of the main process) do not run as root, but rather as the user apache, how can you allow both your user account and the php scripts to read and write the &lt;br /&gt;
*:necessary files?&lt;br /&gt;
*:: ''Hint:'' You shouldn't be storing the user-uploaded files in public_html (that is only the place for your own web-page files), &lt;br /&gt;
*::''Hint number 2:''  you will need to use chown to change permissions to let user apache have permissions on the user-files (that '''are not''' in the public_html folder). If you don't know what this does or how to do this, look at the [[Apache]] page&lt;br /&gt;
* You should customize your file sharing site by implementing an additional feature or two as part of the '''creative portion'''.&lt;br /&gt;
&lt;br /&gt;
You will probably find the PHP guide on this wiki to be helpful: [[PHP#Other PHP Tips]]&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to follow the conventions of FIEO (Filter Input and Escape Output)'''.  Things you should filter include file names, usernames, and so on.&lt;br /&gt;
* '''Your project must pass the W3C Validator with no errors or warnings'''.  For more information, see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 120 points total. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to GitHub by the end of class on the due date. Commit early and often. Failing to commit by the end of class on the due date will result in a 0. &lt;br /&gt;
&lt;br /&gt;
_____________&lt;br /&gt;
&lt;br /&gt;
# '''Cloud Instance and Web Server (30 Points):'''&lt;br /&gt;
#* You can SSH into your instance using your own custom username and SSH key. Put a screenshot in your repository of your terminal SSH-ing into your instance (15 points)&lt;br /&gt;
#* Your custom username is able to perform SUDO commands. Put a screenshot in your repository of you successfully executing a command with sudo (5 points)&lt;br /&gt;
#* The time zone is correct on your instance. Put a screenshot in your repository of the results of the `date` command (5 points)&lt;br /&gt;
#* The UserDir Apache module is working. Place a file in /home/&amp;lt;username&amp;gt;/public_html and link to the file in your README.md (5 points)&lt;br /&gt;
# '''PHP Calculator (15 Points):'''&lt;br /&gt;
#* The calculator is able to perform all four functions with floating point numbers (2 points each, 8 points in total)&lt;br /&gt;
#* Each function is given as a radio button choice (4 points)&lt;br /&gt;
#* The calculator page passes the W3C HTML validator (3 points)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your individual repo with the the link to your calculator.''''' See the Creative Portion section for more information about .md files.&lt;br /&gt;
# '''Git Tutorial (20 Points):'''&lt;br /&gt;
#* Place the two screenshots displaying the completed levels of the Main and Remote sections in your Individual repo&lt;br /&gt;
# '''File Sharing Site (40 Points):'''&lt;br /&gt;
#* '''''File Management (25 Points):'''''&lt;br /&gt;
#** Users should not be able to see any files until they enter a username and log in (4 points)&lt;br /&gt;
#**: ''Remember that users.txt should be stored in a secure location on your filesystem.  That is, '''you should not be able to type any URL into your browser and see the raw users.txt file!'''''&lt;br /&gt;
#** Users can see a list of all files they have uploaded (4 points)&lt;br /&gt;
#** Users can open files they have previously uploaded (5 points)&lt;br /&gt;
#**: ''Note: Users should be able to open not only plain text files but also other file formats: images, spreadsheets, etc.''&lt;br /&gt;
#** Users can upload files (4 points)&lt;br /&gt;
#**: ''Note: Like users.txt, uploaded files should be stored in a secure location on your filesystem.  That is, '''do not keep your uploads directory underneath a directory served by Apache!'''''&lt;br /&gt;
#** Users can delete files.  If a file is &amp;quot;deleted&amp;quot;, it should actually be removed from the filesystem (4 points)&lt;br /&gt;
#** The directory structure is hidden. Users should not be able to access or view files by manipulating a URL. (2 points)&lt;br /&gt;
#** Users can log out (2 points)&lt;br /&gt;
#**: ''Note: If using session variables, you must ''actually'' log out the user by destroying their session; i.e., don't just redirect them to the login screen.''&lt;br /&gt;
#* '''''Best Practices (10 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (4 points)&lt;br /&gt;
#** The site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C validator (3 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** An .md file is a plain text file called a markdown file  [https://guides.github.com/features/mastering-markdown/ ] .  &lt;br /&gt;
#***The contents of your README.md file are shown on your repo, making it easier for us to grade&lt;br /&gt;
#*** You may style the page with bolding, hyperlings, images, block quotes and lists&lt;br /&gt;
#*** [http://dillinger.io/ This online markdown editor] makes it easy to learn this format  &lt;br /&gt;
#** The link to your file sharing site. '''''We need this to grade your work.'''''&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
=== Creative Portion ===&lt;br /&gt;
&lt;br /&gt;
This module and all future modules will require that you invest some time into creating additional features for your group project.  Plan to invest at least 60 minutes of your time into the creative portion.&lt;br /&gt;
&lt;br /&gt;
* The creative portion is an opportunity for you to learn the material of your own interest.&lt;br /&gt;
* You will not earn credit for a creative-portion feature that simply rehashes something you've already done in a previous module.&lt;br /&gt;
&lt;br /&gt;
If you need ideas for a creative portion, or if you want to know whether or not your creative portion idea is &amp;quot;hard enough&amp;quot;, ask a TA.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Jasonren</name></author>
		
	</entry>
</feed>