ERROR: missing environment variable 'SCRIPT_FILENAME'!

#1
I'm trying to use Perl with Fast CGI but get the above error.

I've set up a Context pointing to my Perl scripts in /cgi-bin/ and everything works fine when the Type is CGI.

I've set up an External app pointing to lsperl.fpl, and linked that to the cgi-bin context (re-configured for Fast CGI). I've also confirmed that I have the FCGI module in my Perl path but, as soon as I try to run the Perl script I get the error.

The log files don't report any problems.

Can anyone suggest what I'm doing wrong?

Many thinaks

Doug
 
#3
Thanks for your quick reply.

Yes I have (with the one difference being that I installed FCGI.pm after installing Litespeed).

I don't have PHP running but do have Ruby on Rails configured (from following the RoR installation guide) which works fine.

I've also set FCGI_PERL_MAX_REQ=1000 in the Perl External App Environment variables.

I'm running v 4.0.11 of Litespeed and perl 5.10.1

TIA

Doug
 
#7
Hi,

Although my setup was substantially the same as yours, I've made an exact copy of your setup but still l, immediately, get the same error.

However, I've noticed a few differences in other aspects of your setup. My www layout follows a rather ancient apache structure which is:-

Doc root = /usr/local/httpd/htdocs
CGI root = /usr/local/httpd/cgi-bin

with all of my scripts in sub directories under CGI root.

I have set up a Fast CGI context called /cgi-bin/ which is linked to lsperld (this pretty much mirrors a Ruby on Rails setup (aside from the additional /dispatch.lsapi Static context) which does work).

I also have a Script Handler that specifies that .pl scripts should us the Fast CGI app.

However, I cannot see anywhere where /cgi-bin/ is mapped to /usr/local/httpd/cgi-bin. This didn't seem to matter when /cgi-bin/ was configured for vanilla CGI but I guess that, maybe, it does for Fast CGI.

Is the missing SCRIPT_FILENAME anything to do with this mapping of the /cgi-bin/ URL to a specific directory?

Incidently, if I remove the /cgi-bin/ context (matching your setup as far as I can tell), I then get a 404 Not Found error when I try and run a script. Looking in the error log it is showing that it cannot find a file in $VH_ROOT/cgi-bin/subdir/script.pl which also suggests that I need to do some sort of specific mapping of Script Root to /cgi-bin/. I've tried a Static context but it did not work.

Help!

TIA

Doug
 
#8
I think I've got it!!

I've just been doing a bit more experimentation, more closely copying the RoR setup I have and I have got it working (whether it is the correct way or not I don't know).

I have done the following:-

1. Created an External App called lsperld which runs lsperl.fpl
2. Created a Script Handler using lsperld and tied to all .pl scripts
3. (A new bit) Created a Fast CGI Context called lsperld which uses the Ext App lsperld
4. (Another new bit) Created a Static context, called /cgi-bin/ with a Location set to my CGI root. I have added the following re-write rules to this Static context (thereby linking it to the Fast CGI Context):-

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /lsperld [QSA,L]

and it seems to have been that which did the trick

I have no idea what the rewrite rules mean and would be grateful for any enlightenment.

Anyway, it seems to work, many thanks for your help.

Doug
 

mistwang

LiteSpeed Staff
#9
I have set up a Fast CGI context called /cgi-bin/ which is linked to lsperld (this pretty much mirrors a Ruby on Rails setup (aside from the additional /dispatch.lsapi Static context) which does work).
that's the problem, you should remove that.
If you want to run script through lsperld, you cannot set script as CGI or FCGI context. have to define a script handler for certain suffix like ".pl". then just use static context to map to the directory holding the script if need.
 
Top