gsd4me has asked for the wisdom of the Perl Monks concerning the following question:

All - is there a better (?define!) alternative to Apache for PC-based (ie non-server based) CGI testing of perl scripts? I have used Apache in the past (I had it working in the old days) but since I have installed Window 10, it has become more of a faff to get correct - missing libraries, license not specified correctly, builds not correct and so on.

I am trying to test an update to my perl-based cgi program.

I understand that cgi has been phased out but our system is so simple that it doesn't need anything fancy, simply a user-interaction that is required with a cgi-generated HTML form, and the system has worked well so far, but it is being updated/upgraded, hence the need to do some testing, and we have no plans at all to change the operation of our packages

<p.We are getting sick of Apache not "doing as it is told" - it is a tool, and users shouldn't have to fight to get tools to work, but that is the case here.

So is there a simpler, easy-to-install/setup/use alternative to Apache that will run offline on a PC, mimicking a server?
  • Comment on Offline alternatives to Apache for CGI testing

Replies are listed 'Best First'.
Re: Offline alternatives to Apache for CGI testing
by chromatic (Archbishop) on Aug 11, 2017 at 16:39 UTC

    I haven't tried this myself, but were I to do so, I might start with Plack::Handler::CGI to wrap the script and Plack::Test to write some automated tests. If you haven't used Plack before, the learning curve takes some time to navigate, but it may pay off quickly as it lets you migrate from standalone CGI files to more modular libraries.

Re: Offline alternatives to Apache for CGI testing
by hippo (Archbishop) on Aug 11, 2017 at 08:29 UTC
    is there a better (?define!) alternative to Apache for PC-based (ie non-server based) CGI testing of perl scripts?

    The alternative I would suggest is not to use a webserver at all. CGI scripts can be perfectly adequately tested without a webserver by setting the environment correctly and optionally providing the input data on STDIN. eg.

    use strict; use warnings; use Test::More tests => 2; $ENV{REQUEST_METHOD} = 'GET'; $ENV{QUERY_STRING} = 'game=chess&game=ludo&weather=dull'; $ENV{PATH_INFO} = '/somewhere/else'; $ENV{PATH_TRANSLATED} = '/usr/local/somewhere/else'; $ENV{SCRIPT_NAME} = '/cgi-bin/foo.cgi'; $ENV{SERVER_PROTOCOL} = 'HTTP/1.0'; $ENV{SERVER_PORT} = 80; $ENV{SERVER_NAME} = 'here.there.com'; my $out = `/path/to/my/script.cgi`; like ($out, qr/Content-type: text\/html/, 'HTML response'); like ($out, qr/foo/, 'Foo found');

    Depending on the actual deliverable, this may well be all you need.

Re: Offline alternatives to Apache for CGI testing
by afoken (Chancellor) on Aug 11, 2017 at 19:41 UTC
    All - is there a better (?define!) alternative to Apache for PC-based (ie non-server based) CGI testing of perl scripts?

    There are a lot of webservers designed to be "small" or "tiny" that can execute CGIs with no or almost no configuration: Busybox bundles a CGI-capable webserver, thttpd can do CGI when enabled (RTFM), mini_httpd can do CGI, tinyhttpd can do CGI. And a little bit of searching will pop up tons of other little webservers.

    but since I have installed Window 10

    Well, don't use Windows ... *SCNR*

    Try VirtualBox. Really. Setting up VirtualBox is just clicking through a standard installer. Download a Debian / Ubuntu / SuSE / Slackware / whatever-you-like setup ISO file, create a new virtual machine in VirtualBox, and install Linux from a virtual CDROM with the ISO file. Set network to bridge mode to make the VM appear in your network as an independant computer.

    Or, use XAMPP for Windows. I don't like it, and should not be used on production machines, but it quickly gives you a working Apache installation, including PHP, Perl, MySQL (MariaDB), Tomcat, an FTP server, a mail server and a lot of other stuff. If you only want a working Apache, choose custom installation and remove anything but Apache.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Offline alternatives to Apache for CGI testing
by Anonymous Monk on Aug 10, 2017 at 23:42 UTC

      Not close enough to apache.

      HTTP::Server::Simple can be used to build a standalone web-based application or turn a CGI into one.

      can means that out of the box it doesn't serve images/files/run cgis. copy/pasting SYNOPSIS gets you 1/3 ... but synopsis's usually aren't well tested.

Re: Offline alternatives to Apache for CGI testing
by Anonymous Monk on Aug 10, 2017 at 23:39 UTC

      Whihch one of those answers is good for the OP?

      I'm pretty sure none of them are, as most of the stuff has been abandoned 10+ years ago, never ran on windows, or its a building block.

      Aside from the same non-starters , maybe there is a usable answer in Lightweight equivalent of Apache/CGI? , TinyWeb looks like the best candidate

Re: Offline alternatives to Apache for CGI testing
by Anonymous Monk on Aug 10, 2017 at 23:14 UTC

    apacheet?

    but FWIW, not being able to get apache running is concerning as other people can get apache running under win 10

      To give some credit to the OP, Apache isn't an install-and-forget software by any means. It's been quite complex for well, since forever, but over the years, there's a lot more detail to manage and take care of, particularly on initial config.

      I'm not putting the software down, as I used it for many years. However, Windows administrators don't normally have to deal with so much config file manipulation, so I understand the concern here. The non-working part is surely due to mis-config of options, but I digress.

      OP here wants a one-off fire-and-forget web server that will present Perl scripts properly within web pages, and personally, I'm curious to find out if anyone else has a solution to this.

        OP here wants a one-off fire-and-forget web server that will present Perl scripts properly within web pages, and personally, I'm curious to find out if anyone else has a solution to this.

        Thats not what he says he wants :)

        Even apacheet requires configuration ( two paths). Here is another "simpler" version of apacheet no webserver(apache)? no problem! test .cgi with Plack/plackup

        To give some credit to the OP, ... I understand the concern here

        Both credits and concern? Spoiler!

        The only reason to use apache on test/dev machine, is if you plan to deploy to apache (or your other test server is broken ), in which case figuring out how to run it is paramount

        The only reason to whine about it when asking for alternatives is if you're hoping someone will hold your hand and fix it

        Whining is for puppies

Re: Offline alternatives to Apache for CGI testing
by gsd4me (Beadle) on Aug 12, 2017 at 10:32 UTC

    Thanks for the input people - some positive contributions, others less so, others with non-technical observations. I shall look at the options specified and see what will work best for us.

    BTW - I mentioned that configuring Apache seems to be such a struggle these days, with many options, configuration specifics and 'hurdles' to get over (cf the problem with 'my' Apache objecting to the licence configuration not being correct - what should it matter on my own PC?).

    In a similar vein, I have just installed the latest Ubuntu on my wife's laptop - completely bare machine, nothing else on HDD, and trying to install the media player VLC was equally fraught with hurdles - needed different libraries, then different packages, then something else, all to simply play a DVD.

    Having worked with computers since the late 1970's, it seems that we are going backwards, away from simplicity wrt installation, updates, upgrades and technology 'advances' and it requires a bit of nous to be able to get things correct, as opposed to just buying the latest device. This may be one of the reasons why the generation older than me (and I'm only talking here of those aged 60+) struggle so much with what is available. The younger generation of developers don't seem to understand the principle that they have to allow for things not being 'perfect' and that deviances have to be catered for. The way I used to explain what I did in the software industry was that if I handled everything that possibly could go wrong (what we called 'defensive programming') then what was left must be right.

    Rant over! Again, many thanks to the Clerical Collective in their monastery

    UPDATE

    I have gone with WAMP package to do my testing, via the suggestions of user afoken, and everything is now hunky-dory: Apache (and everything else installed) without a hitch and I am now testing to my heart's content.