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

I would like to create a web app for my own use. It would run on my box and only listen on 127.0.0.1. It would only need to handle one client at a time (me) and only produce HTML output. It would be a CGI app so I would need an easy way to process form input. And it is also important to me that the server be as minimal as possible with regard to Perl modules needed, as I want it to be relatively easy to install for others.

I looked at CGI::MiniSvr, which might do the job, but the only place I can find it on CPAN is as part of some cvswebedit bundle.

Am I looking in the wrong direction? What modules should I use? Thanks for any help.

Replies are listed 'Best First'.
•Re: Creating a simple HTTPD in Perl
by merlyn (Sage) on Apr 05, 2004 at 21:42 UTC
Re: Creating a simple HTTPD in Perl
by fglock (Vicar) on Apr 05, 2004 at 21:42 UTC
Re: Creating a simple HTTPD in Perl
by Elijah (Hermit) on Apr 05, 2004 at 21:38 UTC
    Why not just run a webserver on your local machine and limit access to it by having it listen on 127.0.0.1? This would be a better solution for you especially if you want to use a CGI app. Web servers such as Apache and IIS have support built into them to support CGI apps in numerous languages. This would be a tedious task to emulate and anyway, why re-invent the wheel?

    www.perlskripts.com
Re: Creating a simple HTTPD in Perl
by tinita (Parson) on Apr 06, 2004 at 07:47 UTC
Re: Creating a simple HTTPD in Perl
by bageler (Hermit) on Apr 06, 2004 at 19:33 UTC
    basic tiny webserver. Actually it could use a good round of golf. Signal handlers can also be added to take care of HUP,INT and TERM to safely reset or kill the daemon.
    local $|=1; use IO::Socket; my $PORT = $ARGV[0] || 9000; # pick something not in +use my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, LocalAddr => 'localhost', Reuse => 1); unless ($server) { logit "can't setup server",0; exit 0; } while (my $client = $server->accept()) { $client->autoflush(1); my $request = <$client>; chomp $request; #do stuff with the request here, like: if ($request =~ m|^GET /(.*) HTTP/1.[01]|) { # some sort of processing, whatever you want } else { print $client "HTTP/1.0 400 BAD REQUEST\n"; print $client "Content-Type: text/plain\n\n"; print $client "BAD REQUEST ($request)\n"; } close $client; }