| ACADEMIC COMPUTING and COMMUNICATIONS CENTER | |||||||||
| |||||||||||||||||
4. Perlwrap | |||||||||||||||||
|
In this section, I concentrate just on how to run a perl script in the ACCC environment. Reasons why you want to do things a certain way, or how they work under the covers, is in another section. |
|||||||||||||||||
| Basics | |||||||||||||||||
|
OK, so you want to go for it. It's as simple as:
|
|||||||||||||||||
| Directories and URLs | |||||||||||||||||
|
The mechanics are fairly simple. You'll need to create a directory, and set file permissions thusly:
cd
mkdir cgi-bin
chmod u+rx cgi-bin
Also, be sure your home directory is publically executable:
chmod a+x ~You only need do all that once. Now you need to create a CGI script. Here's a simple example: #!/usr/local/bin/perl print <<EOF; Content-type: text/plain Hi! This is my first CGI! EOFJust put this into a file called hi.pl in your cgi-bin directory. (I've not explained perl here. If this script does not make sense to you, you will have to learn some perl.) Either copy this by cut-and-paste, or just use these commands:
cd ~/cgi-bin
cp /usr/local/lib/www/hi.pl .
chmod u+rx hi.pl
That's it. Note that however you make your CGI scripts, you
need to give execute permission to the usr. Unlike normal
html files, the CGI scripts do not have to have public
read permissions. (In fact, I recommend against public
read permission. You want the web server to execute your
script, but you generally don't want the public crawling
through your code, looking for vulnerabilities.)
Once your script is set up, all you have to do is run it. In the above case, if your netid happened to be adabyron, you would use the following url:
http://www2.uic.edu/htbin/perlwrap/~adabyron/hi.pl
Obviously, if you were on tigger, you'd use www.uic.edu
instead of www2.uic.edu. Everybody uses
htbin/perlwrap/, and you don't include the cgi-bin
directory, in the same sense that public_html is
not included for regular html files.
|
|||||||||||||||||
| Authenticated Scripts with Bluestem | |||||||||||||||||
|
Anyone at UIC could connect to the above example anonymously. Suppose you wanted to force the user to authenticate, to give you his/her netid, which your script could then process or record. Of course, this is done safely, so that the user's password is never compromised. You can have perlwrap invoke the Bluestem system quite easily. In fact, all you need do is change the url. And, you probably want to modify your script to deal with the authenticated netid. Here's an example script:
#!/usr/local/bin/perl
print <<EOF;
Content-type: text/plain
Hi, $ENV{REMOTE_USER}! This is my second CGI!
EOF
This script is located in /usr/local/lib/www/backatcha.pl.
Copy it to your own cgi-bin directory, set the
file permissions, and try out this url:
https://www2.uic.edu/htbin/perlwrap-auth/~adabyron/backatcha.plNote:
|
|||||||||||||||||
| Debugging | |||||||||||||||||
|
Debugging a CGI script is normally painful. Much worse than
debugging a normal program, because it is hard to make the error
messages come out in a place you can read them. In this
regard, using
Do everything normally, but instead of using |
|||||||||||||||||
| CGI | Previous: 3 Codewrap | Next: 5 Perl |
| 2006-9-29 wwwtech@uic.edu |
|