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

I have just started making a website and am new to perl. I want to be able to test my scripts and web pages before I start paying for web hosting, so I have been trying to do this locally, running ActivePerl in Windows 2000. However, instead of generating a webpage, the perl script just prints the text in a dos command prompt window. How can I get round this? I guess it must be something obvious but I'm just not getting it! Thanks...

Replies are listed 'Best First'.
Re: Testing ActivePerl scripts locally
by jZed (Prior) on Mar 21, 2005 at 02:56 UTC
    You need a local webserver to serve the pages. There are many free and Free webservers for windows. I highly recommend getting Apache - it installs easily on Windows and will provide an environment similar to that provided by the better ISPs. There is a BigApache download that will install perl and Apache and MySQL and mod_perl if those are things you might get into.

    Note: you can test the scripts without the webserver, but for the full effect (i.e. seeing the results of the script in a browser) you'll need a webserver. Well actually you could use just perl to create HTML pages and then view those in a browser, but if you want something that acts like a real CGI script from the browser, you need a webserver.

      Thanks jZed that makes a lot of sense...!
Re: Testing ActivePerl scripts locally
by Popcorn Dave (Abbot) on Mar 21, 2005 at 03:54 UTC
    To add to what jZed said, check out this link for a quick and easy tutorial on how to set up Apache on windows. I'd never done it before and it took me about 20 minutes including reboots!

    Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
Re: Testing ActivePerl scripts locally
by chas (Priest) on Mar 21, 2005 at 04:02 UTC
    You can use the following as a webserver to test your scripts locally (don't use other than for that). I didn't write it (I forget where it came from, but I've used it to test scripts, and it seems to work well.)
    use HTTP::Daemon; use IPC::Open2; $|=1; my $server=HTTP::Daemon->new(LocalPort=>80,LocalAddr=>'localhost'); print "Please contact me at <URL:", $server->url, ">\n"; while($client=$server->accept){ while(my $answer=$client->get_request){ $ans=$answer->as_string; @ans=split /\n/,$ans; $client->autoflush; if($answer->method eq 'GET'){ $path=$answer->url->path; (error,last) unless $path=~s#^/##; if($path=~/html$/i){ $client->send_file_response($path); last; } if($path=~/cgi$/i){ $ENV{REQUEST_METHOD}=$answer->method; $query=$answer->url->query; $ENV{CONTENT_LENGTH}=length($query); $ENV{QUERY_STRING}=$query; $out=`perl $path`; $out=~s/.*?\n\n//s; #remove HTTP header print $client $out; last; } } if($answer->method eq 'POST'){ $path=$answer->url->path; (error,last) unless $path=~s#^/##; if($path=~/cgi$/i){ $query=$answer->url->query; $ENV{REQUEST_METHOD}=$answer->method; for(@ans){ $ENV{CONTENT_LENGTH}=$1 if /Content-Length: (\d+)/; $ENV{HTTP_REFERRER}=$1 if /Referer: (.*)/; } $query=$ans[-1]; undef $CGI;undef $OUT; $pid=open2($CGI,$OUT,"perl","$path") or error; print $OUT $query; close $OUT; @out=<$CGI>; waitpid $pid,0; $out=join "\n",@out; $out=~s/.*?\n\n//s; #remove HTTP header print $client $out; last; } } last; } print "CLOSE: ", $client->reason, "\n" if $client->reason; undef $client; } sub error{ $client->error(RC_FORBIDDEN); print "An error occurred in $ans\n"; }

    chas
Re: Testing ActivePerl scripts locally
by holli (Abbot) on Mar 21, 2005 at 12:06 UTC
    You may find XAMMP interesting. That's a bundle that installs Apache, MySQL, Perl and PHP in one go.


    holli, /regexed monk/