Search code examples
apacheperlcgifastcgi

CGI script: No REQUEST_METHOD in environment


I have a basic Ubuntu server setup and I am attempting to run a CGI script on it but receiving the following error whenever I try running the script via the command line:

CGI will be removed from the Perl core distribution in the next major release. Please install the separate libcgi-pm-perl package. It is being used at /etc/perl/RABX.pm, line 583.

CGI::Util will be removed from the Perl core distribution in the next major release. Please install the separate libcgi-pm-perl package. It is being used at /usr/share/perl/5.20/CGI.pm, line 29.

Status: 400 Bad Request
Content-Type: application/octet-stream
Content-Length: 98

E1:0,3:513,82:No REQUEST_METHOD in environment; this script must be run in a CGI/FastCGI context,N

If I attempt to run the script in the browser I just get a 500 Internal Server Error.

I'm cautious about installing the libcgi-pm-perl package as the CGI script is part of a much larger legacy application that I'm worried will be incompatible with newer packages. I have no idea if this is a real error or more of a warning though.

The bit that really confuses me is the last line. Any advice would be greatly appreciated!

The full script can be seen here: https://github.com/mysociety/writetothem/blob/master/web/services/queue.cgi

Also, apologies if this question is better suited to ServerFault - I wasn't sure where was more appropriate.


Solution

  • whenever I try running the script via the command line ... this script must be run in a CGI/FastCGI context

    You get the error "No REQUEST_METHOD in environment" because you are not running within a CGI context but instead on the command line.

    Please install the separate libcgi-pm-perl package

    I'm cautious about installing the libcgi-pm-perl package as the CGI script is part of a much larger legacy application that I'm worried will be incompatible with newer packages. I have no idea if this is a real error or more of a warning though.

    This is a warning, that you better install libcgi-pm-perl, because CGI.pm will not be included in core perl in the future. The CGI.pm in this package is the same as it was in core perl, so you don't need to worry about having a different module. Of course, it is probably a newer version than you used before. But this was also the case in the past when you used a new perl version.