Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Simple command line web server for running cgis.

by EvdB (Deacon)
on Aug 23, 2004 at 17:20 UTC ( #385153=perlquestion: print w/ replies, xml ) Need Help??
EvdB has asked for the wisdom of the Perl Monks concerning the following question:

Sometimes I want to fire up a websever for a particular directory just to test some scripts. It is a real pain to set up apache for this as it involves editing the httpd.conf file or moving the test files to another directory.

I have searched for some small webservers that can do CGI and can be started with just a command line. I have found a partial answer in mini_httpd. Running something like mini_httpd -p 8080 -c '**.pl' will start a server which uses the current directory as its base, it will listen on port 8080 and will treat anything ending in .pl as a CGI script.

Unfortunately there does not appear to be sensible error logging so a special line is required at the top of each script:

#!/usr/bin/perl open STDERR, ">>errors" if $ENV{SERVER_SOFTWARE} =~ m/^mini_httpd/; use strict; use warnings; use CGI::Carp; use CGI; warn "This is a warning"; print CGI->header; print "Hello"; print "<br>$_ : $ENV{$_}\n" for keys %ENV;

Does anyone have a solution to this problem. I want to start a server from the command line that lets me test scripts. Obviously this server will be very simple, only just enough for CGI scripts.

This is the list of servers I scanned to find mini_httpd.

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re: Simple command line web server for running cgis.
by Aristotle (Chancellor) on Aug 23, 2004 at 17:38 UTC

    Just checking: you know you can simply run CGI scripts from the command line, right? See the documentation on -debug.

    Otherwise, you could also roll your own with HTTP::Daemon — it's not very complicated if you just need something quick and dirty for testing.

    Makeshifts last the longest.

      I knew about -debug in CGI.

      What I want is to fire up a collection of scripts so that they behave (and interact) as they would on a proper web server without setting up the proper webserver. I shall see if I can't roll my own using HTTP::Daemon.

      --tidiness is the memory loss of environmental mnemonics

Re: Simple command line web server for running cgis.
by iburrell (Chaplain) on Aug 23, 2004 at 18:07 UTC
    Check out Jellybean,, by chromatic.
Re: Simple command line web server for running cgis.
by Your Mother (Chancellor) on Aug 23, 2004 at 20:41 UTC

    Boostering for IO::All today. From its POD, the one line webserver.

    perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 +? "./$1 |" : $1) if /^GET \/(.*) / })'

Re: Simple command line web server for running cgis.
by Anneq (Vicar) on Aug 25, 2004 at 00:17 UTC

    Actually, its not that hard to edit the apache config file to do what you want. For example, assuming WinXP, just add something like the following to the end of your httpd.conf file:

    <VirtualHost *:80> ServerName www.sandbox.laptop ServerAlias sandbox.laptop DocumentRoot "C:/www.sandbox.laptop/htdocs" DirectoryIndex index.html ScriptAlias /cgi-bin/ "C:/www.sandbox.laptop/htdocs/cgi-bin/" ScriptAlias / "C:/www.sandbox.laptop/htdocs/" </VirtualHost>

    And then edit your hosts file (on WinXP its C:/WINDOWS/system32/drivers/etc/hosts) like: localhost www.sandbox.laptop sandbox.laptop



Re: Simple command line web server for running cgis.
by EvdB (Deacon) on Aug 26, 2004 at 11:11 UTC
    I have now taken to using boa as the small webserver. I requires one config file (boa.conf) but that can be made generic and just copied over to the correct directory as needed. My config file is:
    Port 8080 ErrorLog error_log AccessLog access_log CgiLog cgi_log DocumentRoot . DirectoryIndex index.html DirectoryMaker /usr/lib/boa/boa_indexer DefaultType text/html AddType application/x-httpd-cgi pl MimeTypes /etc/boa/mime.types
    This then allows you to change to the correct directory and then to type boa -c . to start the server. It handles CGI errors well which makes it better than mini_httpd for this usage.

    --tidiness is the memory loss of environmental mnemonics

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://385153]
Approved by kvale
Front-paged by Anneq
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2016-07-25 19:07 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (226 votes). Check out past polls.