You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Alois Treindl <al...@astro.ch> on 2003/02/12 14:08:20 UTC

source code appears as text listing in browser

I tried to follow instruction in mod_perl developer's cookbook to move 
exitings CGI script to mod_perl.

What happens is that the browser lists the source code of my CGI 
scripts, instead of excuting them, when I create a special mod_perl 
directory with this configuration.

PerlModule Apache::PerlRun
Alias /perl/ /www/atl/cm/
PerlTaintCheck on
PerlSetVar Debug 1
<Location /perl>
   SetHandler perl-script
   PerlHandler Apache::PerlRun
   Options  +ExecCGI
   PerlSendHeader On
   Order deny,allow
   Allow from all
</Location>

The same scripts in the cgi directory do fine, as they always have,
when I run them as regular cgi scripts.

I am using Apache 1.3.27 on HPUX, with mod_perl 1.27

What might I be doing wrong?



Re: source code appears as text listing in browser

Posted by Bernhard van Staveren <ma...@ghostfield.com>.
[snip]

> The same scripts in the cgi directory do fine, as they always have,
> when I run them as regular cgi scripts.
> 
> I am using Apache 1.3.27 on HPUX, with mod_perl 1.27
> 
> What might I be doing wrong?

I've never used Apache::PerlRun to run old CGI scripts, always used
Apache::Registry so this might work for you - YMMV

Alias /cgi-perl /home/whatever/cgi-bin
<Location /cgi-perl>
  SetHandler perl-script
  PerlHandler Apache::Registry
</Location>

Then call scripts as /cgi-perl/yourscript.cgi instead of /cgi-bin/yourscript.cgi

As I said, your mileage may vary - I've always had good success with it, but
a script that's not so nicely written can (and probably will) suck up memory
or cause other "interesting" problems. 

-- 
Bernhard van Staveren   -   madcat(at)ghostfield.com
GhostField Internet     -   http://www.ghostfield.com/
"A witty saying proves nothing, but damn it's funny!" - me, 1998 

Re: source code appears as text listing in browser

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Alois Treindl wrote:
> I tried to follow instruction in mod_perl developer's cookbook to move 
> exitings CGI script to mod_perl.
> 
> What happens is that the browser lists the source code of my CGI 
> scripts, instead of excuting them, 

what this means is that the normal Apache handler that sends static content 
(such as .html files and images) is serving your pages instead of mod_perl - 
a typical problem that usually just boils down to a misconfiguration.

> when I create a special mod_perl 
> directory with this configuration.
> 
> PerlModule Apache::PerlRun
> Alias /perl/ /www/atl/cm/
> PerlTaintCheck on
> PerlSetVar Debug 1
> <Location /perl>
>   SetHandler perl-script
>   PerlHandler Apache::PerlRun
>   Options  +ExecCGI
>   PerlSendHeader On
>   Order deny,allow
>   Allow from all
> </Location>
> 

the easiest way to proceed is to do essentially what the other poster said. 
  I would start by copying your cgi-bin configuration in your http.conf 
(namely, the <Location> container and associated Alias directive) and change 
it to perl-bin.  then check to see whether a simple script behaves the same 
under /cgi-bin/ and under /perl-bin/, for example this env.cgi:

#!/usr/bin/perl

print "Content-type: text/plain\n\n";
print map {"$_ => $ENV{$_}\n"} keys %ENV;

at this point, /perl-bin/env.cgi should show GATEWAY_INTERFACE should be 
CGI/1.1, since you're still under mod_cgi.

anyway, after you get your cgi-bin working in the new location, then try to 
port the config to mod_perl.  first replace

SetHandler cgi-script

with

SetHandler perl-script
PerlHandler Apache::PerlRun

and see what happens - you may have enough to run the scripts under mod_perl 
with that step alone.  try /perl-bin/env.cgi - under mod_perl, 
GATEWAY_INTERFACE is CGI-Perl/1.1 and MOD_PERL is set to something true.

if you're getting errors at this point, check the error_log and try to 
resolve any - mod_perl is pretty descriptive most of the time.  you may need 
to add PerlSendHeader to get your scripts where you want them, but it's not 
required for the above basic steps to get a working config.

lemme know if this helps.

--Geoff