Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems running Perl script using CGI on Unix 1

Status
Not open for further replies.

r18044

Programmer
Mar 13, 2001
6
US
I created a perl script (test.pl) that uses CGI. When I run it on my local NT server (using Xitami). It runs fine. When I ftp it onto our Unix web server and set the permissions to 755 (rwxr-xr-x), the file is accessible through the web but it is displayed as a downloadable text file instead of running the perl code. Are there any paths, variables, etc. that need to be defined on the Unix side? I verified that CGI.pm exists on the Unix side in the '/usr/local/lib/perl5/5.00502' directory but I'm not sure what else is required.

The code is as follows:

#!/usr/bin/perl

# CGI script that creates a fill-out form
# and echoes back its values.

use lib '/usr/local/lib/perl5/5.00502';
use CGI qw:)standard);
print header,
start_html('A Simple Example'),
h1('A Simple Example'),
start_form,
"What's your name? ",textfield('name'),p,
"What's the combination?", p,
checkbox_group(-name=>'words',
-values=>['eenie','meenie','minie','moe'],
-defaults=>['eenie','minie']), p,
"What's your favorite color? ",
popup_menu(-name=>'color',
-values=>['red','green','blue','chartreuse']),p,
submit,
end_form,
hr;


if (param()) {
print "Your name is",em(param('name')),p,
"The keywords are: ",em(join(", ",param('words'))),p,
"Your favorite color is ",em(param('color')),
hr;
}
 
The directory you ftp it into must be the one defined to the web server as containing cgi executables (usually cgi-bin or cgi-local). Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I ftp'd the file into a cgi-bin directory but I don't know if it is defined as one by the web server. Is there a way to check this (without asking the web server admin)?
 
Are you converting the DOS line endings to UNIX flavor?

My humble suggestion....
Do a very simple CGI and see if it works.... like

#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print &quot;<HTML><HEAD><TITLE>A NEW CGI PAGE</TITLE></HEAD>\n&quot;;
print &quot;<BODY><P>Here is the text I want to see</P></BODY></HTML>&quot;;


FTP that onto the server, make sure chmod +x , and hit that uri from a browser. Get that to work. If it works, you know you are in a valid CGI spot (usually .../cgi-bin/) on the server.

If that works, then try one using CGI.pm.


#!/usr/local/bin/perl
use CGI;
$q = new CGI;
print $q->header;
print $q->start_html;
print &quot;<P>Here is what I hoped to see.</P>\n&quot;;
print $q->end_html;


This will confirm that you are, in fact, getting CGI.pm to work. From there, it is a matter of syntax in the code you posted above.


HTH


keep the rudder amid ship and beware the odd typo
 
I tried your simple script and unfortunately it did not work which must mean that this is not a valid cgi-bin directory. Do you know I can define it as a valid cgi-bin directory.
 
What web server are you using in unix? &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
I doubt your service provider would let you specify CGI directories. Instead, you need to ask them which dirs are CGI dirs. Once you know that, ftp your copy of the simplest script above to a valid CGI dir, convert it from DOS to UNIX and make it executable on the UNIX system. I expect you will need to do the DOS->UNIX conversion and set the execute bits with your ftp client. Also, make sure the first line of the Perl code points to the Perl installation on the server, not where it was on your box. That should work. If not, check closely for typos. If no, typos, post the error you get, ver-batim, and we'll go from there.

HTH


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top