1

I really do not get how to run a Perl file. I have uploaded my .pl to the cgi-bin then chmod to 755. Then when i go to run the file i just get a 500 internal server error.

**/cgi-bin/helloworld.pl**


#!/usr/bin/perl

print 'hello world';

Any ideas as to what I am doing wrong?

pnuts
  • 58,317
  • 11
  • 87
  • 139
pjau
  • 915
  • 1
  • 8
  • 14

7 Answers7

15

Read the official Perl CGI FAQ.

That'll answer this, and many other questions you may have.

For example: "My CGI script runs from the command line but not the browser. (500 Server Error)"

Hope this helps!

Anirvan
  • 6,214
  • 5
  • 39
  • 53
10

You probably need something like

print "Content-type: text/html\n\n";

before your print statement. Take a look at http://httpd.apache.org/docs/2.0/howto/cgi.html#troubleshoot

It would help to know what server you are using, and the exact error message that's showing up in the server's logs. I'd guess that, if you are using Apache, you'll see something like "Premature end of script headers".

also
  • 974
  • 7
  • 21
3

Look into using CGI::Carp to output fatal errors to the browser. use CGI::Carp qw(fatalsToBrowser);

Also, please definitely do use the CGI module to output any needed information such as headers/html/whatever. Printing it all is the wrong way to do it.

EDIT: You will also definitely be able to check an error log of some sort.

3

Perhaps you need my Troubleshooting Perl CGI scripts

brian d foy
  • 129,424
  • 31
  • 207
  • 592
2

First, find out the path to perl on that system and make sure the shebang line is correct. Giving more information about the system and the web server would also help others diagnose.

Then, try:

#!/path/to/perl/binary

use strict;
use warnings;

$| = 1;

use CGI qw( :default );

print header('text/plain'), "Hello World\n";
brian d foy
  • 129,424
  • 31
  • 207
  • 592
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
  • nope didn't work. the path is definately /usr/bin/perl the os is linux, its apache – pjau Aug 02 '09 at 21:48
  • @Paul Are you just stringing people along: You do not get a 500 status from Apache without an entry in the error log. Post the information in the error log. There is no point in constantly trying to guess with no information. – Sinan Ünür Aug 02 '09 at 22:32
  • i looked at cpanel >> error log and its not saying anything in there – pjau Aug 02 '09 at 23:04
  • 3
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html: HTTP header fields, which include general-header (section 4.5), request-header (section 5.3), response-header (section 6.2), and entity-header (section 7.1) fields, follow the same generic format as that given in Section 3.1 of RFC 822. Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive. – ysth Aug 03 '09 at 00:09
1

Make sure that you can run the script from a shell prompt, without invoking it through Perl. In other words, you should be able to go to your cgi-bin directory and type:

./helloworld.pl

and get output. If that doesn't work, fix that. In looking at the output, the first line must be:

Content-Type: text/html

(Or text/plain or some other valid MIME type.)

If that's not the case, fix that.

Then you must have an empty line before the body of your page is printed. If there's no empty line, your script won't work as a CGI script. So your total output should look like this:

Content-Type: text/html

hello world

If you can run your script and that's the output, then there's something weird going on. If Apache is not logging the error to an error_log file somewhere, then maybe there's some problem with it.

Rafe
  • 3,056
  • 1
  • 22
  • 25
0

Did you enable Apache to server .pl files as CGI scripts? Check your Apache config file, or (quick but not guaranteed test) try changing the file extension to .cgi. Also, make sure your shebang line (#!) is at the very top. Finally, check the line endings are Unix if your server is Linux. And yes, test it from the command-line, and use strict; for better feedback on potential errors.

Dave Everitt
  • 17,193
  • 6
  • 67
  • 97