I’m having problems with my Perl script executing. I can execcute it at the DH command prompt with the Perl filename command, but when my .shtml code encounters the script from the browser, I get an “Internal Server Error” page. The file “test.pl” is simply referred to as a form ACTION. Any help would be appreciated.
- Check the permissions of the CGI script file and the directory it is in (both should be 755)
- Check the error handling routines. Error messages or spurious output generated before HTTP headers will cause “Premature end of headers” in the error.log file.
Perl / MySQL / HTML+CSS
Thanks for your suggestions.
The permissions level are all 755
The error in the error log says:
[Thu Jan 26 16:52:42 2006] [error] [client 22.214.171.124] Premature end of script headers: /home/schwemer/secondbeginnings.org/Second Beginnings Web Page test_files/test.pl
But this program runs at the command line with Perl test.pl
That doesn’t mean squat when it comes to CGI.
For CGI, Perl scripts will be executed by the web server in a special environment. Also the web server will expect the beginning of the output to be a valid set of HTTP headers.
The special environment doesn’t exist when run from the command line. You have not mentioned whether or not the output starts with a valid set of HTTP headers or not.
The Apache error indicates you are not generating a valid set of HTTP headers. Please ensure you are generating a valid set of HTTP headers.
Example code below:
my @http_headers = (
my $content = <<TEXT;
This is an example of a CGI script.
response headers separated by linebreaks
join("\n", @http_headers) .
double linebreak to separate headers from content
One can also use the CGI::Carp module. From CGI::Carp documentation:
If you want to send fatal (die, confess) errors to the browser, ask to import the special ``fatalsToBrowser’’ subroutine:
use CGI::Carp qw(fatalsToBrowser);
die “Bad error here”;
Fatal errors will now be echoed to the browser as well as to the log. CGI::Carp arranges to send a minimal HTTP header to the browser so that even errors that occur in the early compile phase will be seen. Nonfatal errors will still be directed to the log file only (unless redirected with carpout).
Perl / MySQL / HTML+CSS
Do you really need to do what you are doing in Perl?
If you are unfamiliar with perl or CGI programming, then its going to be a really hard slog to get something working.
PHP has a much less steep learning curve.
I agree with Herods. If you’re really unfamilar with Perl, I highly suggest NOT to use it for CGI programming. CGI development is MUCH more error prone than your standard language built for web programming (PHP, JSP, ASP, etc).
I do also recommend trying out PHP. Unlike CGI, PHP will be less likely to fail with cryptic error messages.
Like Atropos7 said, just cause it works on the command line doesn’t mean it’ll work on the CGI level. There’s just too many other factors involved: permissions, extra characters, syntax/command errors, etc. Perl is not a newbie friendly language for CGI development these days. Go with PHP.
No problem. I now have it working. The referenced site is a good one. With test programs and all. I did change the Shell type. Can someone tell me what the different “types” are all about? Is there an advantage to one over the other? This is in the Manage Users area when you edit a user profile.
Purely based on personal preferences. Each shell has it’s own set of commands. A user will use a paticular shell they’re use to cause of it’s commands and such.
Nothing more than personal preferences.