User Tools

Site Tools


techstaff:how_to_use_cgi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
techstaff:how_to_use_cgi [2016/01/06 11:21] chudlertechstaff:how_to_use_cgi [2016/04/22 16:05] – [Example] kauffman
Line 1: Line 1:
-====CGI Programming==== +======CGI Programming======
 The purpose of the CGI service is to allow CS users to learn CGI programming and make small, dynamic sites in their course work. The purpose of the CGI service is to allow CS users to learn CGI programming and make small, dynamic sites in their course work.
  
-Large off-the-shelf web applicationssuch as wikis, picture galleries, bulletin boards, publishing platforms, etc, are prohibited.+These mechanisms are valid for any CS computer. linux.cs.uchicago.edu is recommended for anyone that understands (SSH)otherwise any machine in our lab will do.
  
-To use our CGI server, you must first be registered in a class that requires it.+To use our CGI server, you must first be registered in a class that requires it. Your instructor will let techstaff know of this requirement ahead of time and you will automatically get access.
  
-CGI programs may be written in many languages, including perl, python, php, shell, C, etcExcept for PHP programs (extension .php), the programs must be named with the filename extension .cgi+=====Directories===== 
 +All files related to the course will be hosted out of your home directory in a folder called ''%%~/cs%%''A folder for the course you are taking will automatically be created in the ''%%~/cs%%'' directory. For example:''%%~/cs/cs10100%%''
  
 ====File Permissions==== ====File Permissions====
-.cgi files run under the username that owns them. These program filesas well as datafiles they read, may be set to permissions 700 and 600, to protect passwords or code.+Techstaff does set some extended permissions on these [[techstaff:how_to_use_cgi#directories|directories]] so they should **not** be movedIf you do end up moving or modifying them, it will result in you not being able to access your site.
  
-html files should be set to 644, and directories should be set to 755.+You should not have to worry about modifying any permissions below the ''%%~/cs%%'' directory.
  
-php code does not go through suexec (i.e. runs under a standard unpriviledged user, such as www), and can be 644. 
  
-=====Example 1: Hello World via Perl=====+=====Example===== 
 +PHP is a language designed explicitly for web programming. A single line in the file html/hello.php will do.
  
-change directory to the directory created for you for the course that you are taking (YOU put the name of the course in $COURSE_NAME, such as "cs101" or "mpcs53001":+In this example please keep in mind that ''%%<hostname>%%'' will be provided by your instructor.
 <code> <code>
-cd ~/cs/$COURSE_NAME +<?php print("Hello World!\n"); ?>
-</code> +
- +
-Now create a file named hello.cgi with three lines of perl code: +
-<code> +
-#!/usr/bin/env perl +
-print "Content-type: text/html\n\n"; +
-print "Hello World!\n";  +
-</code> +
- +
-Set the permissions to be executable, then test it at the command line: +
-<code> +
-chmod +x hello.cgi +
-./hello.cgi +
-</code> +
-output: +
-<code> +
-Content-type: text/html +
-Hello World! +
-</code> +
- +
-The first line printed from any cgi program must be a Content-type: line, followed by a blank line. Anything else will cause an error. +
- +
-All cgi programs must have the filename extension .cgi (an exception to this rule is extension .php for PHP programs) +
- +
-Running the program from the command line is a good way to test your program before accessing it via the web. +
- +
-Now try to run the program from your browser. Assuming your CS username is fred, and the cgi server you use is mpcs53001 +
-<code> +
-http://mpcs53001.cs.uchicago.edu/~fred/hello +
-</code> +
- +
-=====Example 2: Hello World via PHP===== +
-PHP is a language designed explicitly for web programming. A single line in the file public_html/hello.php will do. Remember, the file must be world-readable: +
-<code> +
-<? print("Hello World!\n"); ?>+
 </code> </code>
 You can run your php file from the command line: You can run your php file from the command line:
Line 63: Line 28:
 Or from your browser: Or from your browser:
 <code> <code>
-http://mpcs53001.cs.uchicago.edu/~fred/hello+http://<hostname>.cs.uchicago.edu/~user/hello.php
 </code> </code>
  
-====Debugging==== 
-Debugging cgi programs can be tricky, because they run on a server you cannot log into, and many errors just produce the unhelpful message Internal Server Error. 
- 
-Make sure the cgi program is executable, and all directories leading to it are world-executable. 
- 
-Run your cgi program at the command line. The first line must be a Content-type: line, followed by a blank line, followed by valid html. 
  
-For additional assistance with this service, email techstaff@cs.uchicago.edu.+For additional assistance with this service, email [[techstaff@cs.uchicago.edu]].

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki