1
#!C:/perl/bin/perl.exe
use CGI;

my $q = CGI->new;
print $q->header('text/plain'),
    "Hello ", $q->param('name');

#CONVERTED PSGI PAGE

#!C:/perl/bin/perl.exe
use CGI::PSGI;

my $app = sub {
    my $env = shift;
    my $q = CGI::PSGI->new($env);


    return [ 
        $q->psgi_header('text/plain'),
        [ "Hello ", $q->param('name') ],
    ];
};

I run this cgi.pl in apache server as http://localhost/cgi-bin/cgi.pl

but I cant able to run the converted psgi.pl in apache server its displaying please help Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    `CGI` - is one specification what uses the Apache and/or other web-servers. `PSGI` is **another** specification. You can run `CGI` applications under the PSGI-servers (by using `CGI::PSGI`), but you can't run an PSGI application as plain CGI-script. For PSGI app you __dont need__ apache. (if want use apache, you could: 1.) run your PSGI app behind reverse proxy, or 2.) use Plack::Handler::Apache2 or such... – clt60 Feb 04 '15 at 12:31
  • "More information about this error may be available in the server error log" - That sounds like it might be a clue. What does the server error log say? – Dave Cross Feb 04 '15 at 13:29
  • I can able to run it now using plack::runner module – kiran reddy Feb 05 '15 at 10:11

1 Answers1

0

CGI and PSGI are two different specifications of how a web server and an external program communicate.

Under CGI, the web server expects to receive text output from the program, consisting of the HTTP Response headers, a blank line, and the HTML rendered by the program.

The CGI module implements this logic for the apache server, and if the output from the program does not comply, apache reports the 500 error.

Under PSGI, the web server expects the program to return a three element list consisting of the HTTP response code, the HTTP Response headers, and the HTML rendered by the program.

So you can see that a program conforming to the PSGI spec would confuse the mod_cgi.

So you need to install an apache module that implements PSGI, or employ a Perl module (the CGI::PSGI docs suggest CGI::Emulate::PSGI ) that will accept your PSGI list and convert to CGI for you.

Len Jaffe
  • 3,442
  • 1
  • 21
  • 28