Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Perl in CGI

by monoxide (Beadle)
on Oct 28, 2004 at 10:47 UTC ( #403342=perlquestion: print w/replies, xml ) Need Help??

monoxide has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone,
I am trying to test a CGI script that i am in the proccess of writing. I have Perl and IIS installed on my work computer, and i use this to test my script and it works fine, but when i upload it to my web host (using apache) to test it, it falls apart and gives me a 500 error, Internal Server Error. I tested the script on the server using SSH and perl and got the output below (the same as on my computer),
Content-Type: text/html <html> <head> <title>Search Page</title> </head> <body> <font style="font-family: Verdana, Arial, Helvetica, sans-serif; font- +size: 10px;"><form action="?op=search"> <input type="hidden" name="field" value="__FORM__"> <b>Search this database:</b><br>First Name: <input type="text" name="F +irst Name"><br> Email: <input type="text" name="Email"><br> Gender: <input type="radio" name="Gender" value="Male"> Male <input ty +pe="radio" name="Gender" value="Female"> Female <br> Recieve Promotional Material: <input type="checkbox" name="Recieve Pro +motional Material"><br> <input type="submit"> </form> <a href="?op=add">Add a record</a></font> </body> </html>
When i check the error log it says that the headers where cut short prematurely. But the only required header is Content-Type right?

Help would be appreciated...

Replies are listed 'Best First'.
Re: Perl in CGI
by pelagic (Priest) on Oct 28, 2004 at 10:52 UTC
    monoxyde,
    - go check the file permissions of your uploaded file.
    - verify whether you got some Windows style line endings in your script (CRLF) and remove those with eg:
    perl -pi -e'tr/\015//d' your_filename

    pelagic

      Permissions are definitely one to check as Apache (certainly if it's on *nix) is probably tighter on user permissions. Also, it may be case sensitive whereas Windows lets you get away with all sorts.

      --- Jay

      All code is untested unless otherwise stated.
      All opinions expressed are my own and are intended as guidance, not gospel; please treat what I say as such and as Abigail said Think for yourself.
      If in doubt ask.

        If it was permissions, it would more likely be a 'Permission Denied' error....
Re: Perl in CGI
by tachyon (Chancellor) on Oct 28, 2004 at 11:14 UTC

    Help would be appreciated...

    CGI Help Guide

    Did you try to run it as ./script.pl through SSH. That is how Apache runs it. I suspect you did perl script.pl. Two things. chomd 755 script.pl, then try ./script.pl. If that works wohoo, if not RTFM above. perl -pi 's/\r//' script.pl would be next on the list, followed by which perl.

Re: Perl in CGI
by gellyfish (Monsignor) on Oct 28, 2004 at 11:06 UTC

    As well as the DOS line-ending issue that others have mentioned, it might also be the shebang (#!/usr/bin/perl) either being missing or not having the correct path to perl (I am assuming the server is some Unix like OS), you don't need this on windows as IIS uses the extension of the script to know which interpreter to use, but it is necessary on Unix to run a script as an executable. It could also be due to the permissions of the script file - it needs to be executable and readable by the user that the web server process runs as.

    /J\

Re: Perl in CGI
by Mutant (Priest) on Oct 28, 2004 at 11:00 UTC
    More than likely, you saved the file with windows new lines. Hopefully, your editor has an option to save it as unix.
Re: Perl in CGI
by monoxide (Beadle) on Oct 28, 2004 at 12:19 UTC
    Thanks guys, it was the permissions. Stupid me... Oh well i'm new to perl and it didnt even occur to me. I have used mainly php in the past and that doesn't require permissions.

      Er, yes it does, just not the executable permission:

      [jonathan@orpheus html]$ GET http://localhost/index.php <html> <body>Test</body></html> [jonathan@orpheus html]$ chmod 600 index.php [jonathan@orpheus html]$ GET http://localhost/index.php <br /> <b>Warning</b>: Unknown(/var/www/html/index.php): failed to open stre +am: Permission denied in <b>Unknown</b> on line <b>0</b><br /> <br /> <b>Warning</b>: (null)(): Failed opening '/var/www/html/index.php' fo +r inclusion (include_path='.:/usr/lib/php/:/usr/share/pear/') in <b>U +nknown</b> on line <b>0</b><br />
      Eugh.

      /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://403342]
Approved by b10m
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2021-02-24 17:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?