Creating and Using CGI Applications
This document was written by CS 290W TA David Corcoran and was last
modified
- You should create a cgi-bin directory in your www directory.
Do this within your www directory by typing mkdir cgi-bin.
Then make this directory world-readable and executable via
chmod a+rx cgi-bin. You really do not have to have
your cgi applications in a separate directory named cgi-bin. They can
be in your www folder. But, we strongly suggest that you put them in
a separate folder just as you do your images and Java classes.
- Copy the test CGI script test.pl
into your cgi-bin directory. Do this by going to your cgi-bin
directory and typing the command
cp /home/champion/v/bxd/test.pl test.cgi. Notice
that you have gotten a Perl program (.pl) and renamed it test.cgi.
Many Web servers require applications to have the .cgi suffix. Make
test.cgi world-readable and executable via
chmod a+rx test.cgi.
- Copy the CGI parser cgi-lib.pl
into your cgi-bin directory. This file will make it easier for you to
write CGI programs in Perl that handle information sent by Web
browsers. Do this by going to your cgi-bin directory and typing the
command
cp /home/champion/v/bxd/cgi-lib.pl cgi-lib.pl. Make
cgi-lib.pl world-readable and executable via
chmod a+rx cgi-lib.pl.
- Copy the test HTML file
perltestcgi.html into your www
directory. Do this by going to your www directory and typing the
command
cp /home/champion/v/bxd/perltestcgi.html perltestcgi.html.
Make perltestcgi.html world-readable via
chmod a+r perltestcgi.html.
- Test the CGI script by pulling up the perltestcgi.html in your
web browser, entering your name, and verifying your name comes back on
the following page.
If all goes well, and your name shows up on the page following the
text field, then your cgi-bin directory is set up properly. You can
now write your own Perl scripts, name them something.cgi, and run them
from your cgi-bin directory.