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?

7
  • Does your webserver error logs provide any enlightening information? Commented Aug 2, 2009 at 19:29
  • Which webserver, and which operating system? Commented Aug 2, 2009 at 19:32
  • I don't see anything in the error log in cpanel. I am unix linux. Commented Aug 2, 2009 at 19:34
  • Not relevant to your problem, but #!/usr/bin/env perl is preferred Commented Aug 2, 2009 at 19:42
  • 1
    @William Pursell no, not really. Commented Aug 2, 2009 at 21:39

7 Answers 7

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!

Sign up to request clarification or add additional context in comments.

Comments

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".

2 Comments

Just added that line and it isn't helping.
Using print like that is considered bad form. Look into the CGI module.
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.

1 Comment

Don't use the CGI module for output. That's so 1990. Use templates instead. :)
3

Perhaps you need my Troubleshooting Perl CGI scripts

Comments

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"; 

4 Comments

nope didn't work. the path is definately /usr/bin/perl the os is linux, its apache
@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.
i looked at cpanel >> error log and its not saying anything in there
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.
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.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.