Tutorial :Trying to run perl scripts with fast-cgi and lighttpd, but file just downloads



Question:

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!


Solution:1

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


Solution:2

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);  }  


Solution:3

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.


Solution:4

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »