Smallest Text Small Text Medium Text Large Text

CGI Scripts


The campus webserver permits running of CGI scripts through CGIwrap, which assures that your scripts run under your own account. Although other languages could potentially be used, just about everyone uses Perl for CGI scripts. You may either import scripts that you find out on the Internet or write them yourself. To enable them to run you must create a "cgi-bin" directory under your htdocs directory and make sure that the permissions allow public read and execute access but not write access. Fortunately that is the normal default for directories.

Place your CGI scripts inside your "htdocs/cgi-bin/" directory and set their permissions to the same values (owner: read, write, execute; group: read, execute; public: read, execute, ie. Unix permission code 755). You may also place the scripts in subdirectories of your "cgi-bin" directory if you prefer to organize them that way.

Use the ".cgi" extension on the name for your script, eg: "takeform.cgi".

The first line of your Perl CGI scripts should be either:


#!/usr/local/bin/perl

or:

#!/usr/bin/perl

The syntax for this line is strict; do not include anything else on this line, not even a blank character at the end. It's generally best to check the syntax of your script on your own system with your local version of perl before trying it out as a CGI. Faculty and staff may also use vanilla.csulb.edu for that purpose.

To call your CGI script, use a URL in the following format:

http://www.csulb.edu/~username/cgi-bin/scriptname.cgi

Use your own account name after the tilde (in place of "username"). Typically you would include this URL as the action to be taken by a form that submits data to the CGI script.



Pitfalls to Avoid:

  • To guarantee that your script gets transferred properly, use ASCII text mode to upload it with FTP instead of Binary mode. The most frequent cause for script failures is transfer of extraneous characters from the PC by use of Binary FTP mode.
  • Make sure that your permissions are correct, both on the script itself and on the directories above it. In particular, scripts will be rejected if any of these has public write permission (which of course would be a very bad idea anyway).
  • Only use plain ascii text files for CGI scripts. Word processing documents will need to be exported into plain text before being uploaded.
  • Be sure to include the ".cgi" extension for your script name. If you omit the extension, your script will not run; instead a listing of the script will be displayed.