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
techstaff:how_to_use_cgi [2016/01/06 11:21] chudlertechstaff:how_to_use_cgi [2021/09/22 16:16] (current) – removed ctopper
Line 1: Line 1:
-====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. 
- 
-Large off-the-shelf web applications, such as wikis, picture galleries, bulletin boards, publishing platforms, etc, are prohibited. 
- 
-To use our CGI server, you must first be registered in a class that requires it. 
- 
-CGI programs may be written in many languages, including perl, python, php, shell, C, etc. Except for PHP programs (extension .php), the programs must be named with the filename extension .cgi 
- 
-====File Permissions==== 
-.cgi files run under the username that owns them. These program files, as well as datafiles they read, may be set to permissions 700 and 600, to protect passwords or code. 
- 
-html files should be set to 644, and directories should be set to 755. 
- 
-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===== 
- 
-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": 
-<code> 
-cd ~/cs/$COURSE_NAME 
-</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> 
-You can run your php file from the command line: 
-<code> 
-php hello.php 
-</code> 
-Or from your browser: 
-<code> 
-http://mpcs53001.cs.uchicago.edu/~fred/hello 
-</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. 
/var/lib/dokuwiki/data/attic/techstaff/how_to_use_cgi.1452100910.txt.gz · Last modified: 2016/01/06 11:21 by chudler

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki