How can I run my perl CGI script without apache?

旧巷老猫 提交于 2019-12-07 05:34:44

问题


How can I run my perl CGI script without apache? This is for testing purposes, so some kind of single-process server that processes only one request at time should be enough for me.


回答1:


Script shoud be run as specific user and currently I do not want to setup suexec on testing apache.

There is nothing preventing you from duplicating the requisite Apache configuration except for the user under which httpd is going to be run, the interface/port to bind to and possibly the cgi-bin directory and running a separate copy of httpd (with the -f option). That would be the safest way to test the application in the environment it is supposed run.

See Starting Apache:

it is possible to specify its location at run time using the -f command-line option as in

/usr/local/apache2/bin/apachectl -f /usr/local/apache2/conf/httpd.conf



回答2:


Plack::App::WrapCGI or Plack::App::CGIBin represent one way to do this (together with plackup and the default single-threaded Plack HTTP server) but it's not running the CGIs in the context they really expect to be run in (a standalone process) so it's not entirely pretty (the same caveats apply as using modperl registry, more or less). I'm not aware of a pure-perl webserver that actually forks and runs CGI as CGI (nor a non-perl one that does CGI and requires zero config, although lighttpd comes close).

The reason why "are you using CGI.pm" is a relevant question is because if you haven't already started the application you might want to consider writing against pretty much anything else, e.g.

  • Web::Simple
  • CGI::Application
  • Catalyst
  • Mason
  • Mojolicious
  • Dancer

(in random order to hide my obvious favoritism) and gain the ability to easily run the same app as a standalone HTTP server, FastCGI, mod_perl app, or plain CGI if push comes to shove, and without the impedance mismatch that you get when writing to CGI.pm's interface




回答3:


Since you mentioned in the comments that you're using CGI.pm, note that CGI.pm offers a range of options for running CGI scripts from the command line. See http://perldoc.perl.org/CGI.html#DEBUGGING. Even without CGI.pm, you could always just fake up the necessary environment variables and pipe in your file. Basically all you need to do to run a CGI from the command line is to set up

 QUERY_STRING = blah=x&fu=bar

for GET methods, or

 CONTENT_LENGTH = length of your file

for POST methods.




回答4:


Get yourself a virtual machine and do whatever you like with it, including running apache. Duplicate as much as your target setup as you can.



来源:https://stackoverflow.com/questions/2583405/how-can-i-run-my-perl-cgi-script-without-apache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!