techstaff:how_to_use_cgi
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
techstaff:how_to_use_cgi [2016/01/06 11:21] – chudler | techstaff: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 applications, such 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 | + | =====Directories===== |
+ | All files related to the course will be hosted out of your home directory | ||
====File Permissions==== | ====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. | + | Techstaff does set some extended permissions on these [[techstaff: |
- | html files should | + | You should |
- | php code does not go through suexec (i.e. runs under a standard unpriviledged user, such as www), and can be 644. | ||
- | =====Example | + | =====Example===== |
+ | PHP is a language designed explicitly for web programming. A single line in the file html/ | ||
- | change directory to the directory created for you for the course that you are taking (YOU put the name of the course | + | In this example please keep in mind that '' |
< | < | ||
- | cd ~/ | + | <?php print(" |
- | </code> | + | |
- | + | ||
- | Now create a file named hello.cgi with three lines of perl code: | + | |
- | < | + | |
- | # | + | |
- | print " | + | |
- | print "Hello World!\n"; | + | |
- | </ | + | |
- | + | ||
- | Set the permissions to be executable, then test it at the command line: | + | |
- | < | + | |
- | chmod +x hello.cgi | + | |
- | ./ | + | |
- | </ | + | |
- | output: | + | |
- | < | + | |
- | Content-type: | + | |
- | Hello World! | + | |
- | </ | + | |
- | + | ||
- | The first line printed from any cgi program must be a Content-type: | + | |
- | + | ||
- | 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 | + | |
- | < | + | |
- | http:// | + | |
- | </ | + | |
- | + | ||
- | =====Example 2: Hello World via PHP===== | + | |
- | PHP is a language designed explicitly for web programming. A single line in the file public_html/ | + | |
- | < | + | |
- | <? print(" | + | |
</ | </ | ||
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: | ||
< | < | ||
- | http://mpcs53001.cs.uchicago.edu/ | + | http://< |
</ | </ | ||
- | ====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: | ||
- | For additional assistance with this service, email techstaff@cs.uchicago.edu. | + | For additional assistance with this service, email [[techstaff@cs.uchicago.edu]]. |