views:

1669

answers:

8

The problem is my .pl script is downloaded as a blank file instead of being executed.

I read: http://redmine.lighttpd.net/wiki/lighttpd/ApplicationsUsingLighttpd

My dispatch.fcgi is the following: (it is located in usr/bin/

#!perl
#!/usr/bin/perl
use strict;
use CGI::Fast;
use Embed::Persistent; {
my $p = Embed::Persistent->new();
while (new CGI::Fast) {
my $filename = $ENV{SCRIPT_FILENAME};
my $package = $p->valid_package_name($filename);
my $mtime;
if ($p->cached($filename, $package, \$mtime)) {
eval {$package->handler;};
}
else {
$p->eval_file($ENV{SCRIPT_FILENAME});
}
}
}

This is my code in my lighttpd config file:

".pl" =>
((
"fastcgi.debug" => 1,
"bin-path" => "/usr/bin/dispatch.fcgi",
"socket" => "/tmp/fcgi.socket",
"check-local" => "disable",
"min-procs" => 1,
"max-procs" => 5,
"idle-timeout" => 20
))

I had to install CGI.pm and the cpan module embed. Now I do not get any errors in my server log, but as I said, the script just downloads.

Thanks for any help!

A: 

Your webserver found the code too hard to read due to the lack of indentation, and was therefore unable to handle it correctly.

jrockway
That really isn't helpful.
Danny
Really? I totally didn't realize that...
jrockway
A: 

Hmm, adding:

use CGI::Carp qw/fatalsToBrowser/;

still just pops up a save file window.

This is my testperl.pl file I am trying to run:

#!/usr/bin/perl
use CGI::Carp qw/fatalsToBrowser/;
print 'Hello world.';

Maybe I'm not supposed to use the path to the regular perl file since I am using fastcgi?

The script runs in the terminal fine.

Thanks for your help. Oh, and my code is indented, just copy and paste messed it up.

A: 

It appears that you are not sending the correct headers. Use the "header" function in the CGI module to emit the headers

$cgi = new CGI;
$cgi->header();

Then you should be good to go.

For more information check out the header documentation:

http://cpansearch.perl.org/src/LDS/CGI.pm-3.43/cgi_docs.html#header

Cody Caughlan
print $cgi->header; - it doesn't output by itself.
ijw
A: 

Thanks Cody, but unless I did that wrong, it still downloads a blank file with the same name (testperl.pl).

I can't figure it out. I have the testperl in my root directory and I got to localhost/testperl.pl. I have the testperl.pl chmodded to 755 (but I've tested it with different values)...

This is the latest testperl.pl script:

#!/usr/bin/perl
$cgi = new CGI;
$cgi->header();
print 'Hello world.';

Maybe I have the dispatched script wrong, but I just copied the first one on:

http://redmine.lighttpd.net/wiki/lighttpd/ApplicationsUsingLighttpd

into a new file, and my config bin-path points to it. It used to give me errors, but I fixed those. When I have my server running, I have 5 files in my tmp directory:

lighttpd.fcgi.socket-0 lighttpd.fcgi.socket-1 lighttpd.fcgi.socket-2 lighttpd.fcgi.socket-3 lighttpd.fcgi.socket-4

So it seems like the dispatcher is working somewhat.

Thanks

A trivial test - 'perl testperl.pl' on the command line - shows that this has syntax errors. Fix those first. Specifically, 'usr CGI;' and 'print $cgi->header;' and remember to keep testing your scripts...
ijw
"use CGI;" even.
ijw
+1  A: 

Thank you!

#!/usr/bin/perl -w
use strict;
my $cgi = new CGI;
print $cgi->header();
print 'Hello world.';

works! But, I am wondering why I need to print the headers to get it to work with fastcgi and lighttpd. I have a large script someone else wrote that works on my apache and regular cgi server. I guess I have to modify it to work on my new server.

The problem is I think printing the header might mess up the script because it does something like printing html that gets executed.

Thanks again

The CGI spec requires that a header is prepended to the actual content that will be interpreted by the client.
hillu
A: 

Have carp write to a file and look there for problems.

BEGIN {
use CGI::Carp qw/carpout/;
open LOG, ">>", "carp.log" or die("Cannot open file: $!\n");
carpout(LOG);
}
A: 

Make sure static exclude is set for the extensions. Something like...

static-file.exclude-extensions = ( ".php", ".pl" )

Or it will just download the file like any other.

Yoda
A: 

I also have the same problem. How can I set static-file.exclude-extensions=(".php",".pl");

keiko