Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Perl & Personal Web Server

by Anonymous Monk
on Mar 02, 2001 at 03:32 UTC ( #61692=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I hope this is a good place to ask this. How can I work with PWS and Perl? I have an old version of Perl and I want to test some scripts before sending it to my web site. But how can I execute my scripts, I mean, How do PWS knows where Perl is? The firs line of my programs is #! usr/bin/perl but while testing it in PWS in my computer? I hope you can help me.... Thank you for this site.... :)

Replies are listed 'Best First'.
Re: Perl & Personal Web Server
by dws (Chancellor) on Mar 02, 2001 at 04:58 UTC
    PWS executes Perl CGIs just fine. I do a lot of development using PWS on both Win98 and NT, then upload to my ISP (which runs Apache on FreeBSD). It's a reasonable development environment.

    The trick is to convince PWS that .cgi (or .pl) means Perl. This requires editing the registry. (The ActiveState installer is supposed to do this, but I've found it to be less than reliable.)

    Here's what you need to do:

    1. Install PWS
    2. Install ActiveState Perl
    3. Use the Personal Web Manager control to stop PWS
    4. Edit the registry as described below
    5. Reboot the machine (optional on NT, required on 98)
    6. Use the Personal Web Manager control to start PWS

    You should now be able to execute CGIs.

    To edit the registry, do the following:

    1. Start regedit (Start / Run / regedit).
    3. Open SYSTEM
    4. Open CurrentControlSet
    5. Open Services
    6. Open W3SVC
    7. Open Parameters
    8. Open ScriptMap
    9. Edit / New / String Value
    10. Name the new string ".cgi"
    11. Double-click on ".cgi" to open an edit dialog
    12. Type c:\perl\bin\perl.exe %s %s
    13. Click OK
    14. Close regedit

    The kicker is that if you get these steps wrong and set up the scriptmap with a bad .cgi string, you'll need to uninstall and reinstall PWS. (PWS extracts the scriptmap settings and caches them in its MetaBase, and if a bad string gets in there, you can be SOL with PWS, at least in Win98. The MetaBase doesn't have good editing tools.)

    (Update: Oh yeah, you need to use the Personal Web Manager control set set "execute" permission on each directory that you want to run CGIs from.)

    Here's test.cgi, a handy script to drop into C:\InetPub\scripts\ for testing. Once you can hit http://localhost/scripts/test.cgi, you're on the air.

    #!/usr/bin/perl -w print "Content-type: text/html\n\n"; print "<html><body><pre>"; foreach $key ( sort keys %ENV ) { print $key, ": ", $ENV{$key}, "\n"; } print "</pre></body></html>\n";
      Nice post, dws. Shouldn't you get the youngsters off to a good start, though, with a rudimentary CGI module script?
      #!/usr/bin/perl -w use strict; use CGI qw(:standard); print CGI::header(),"\n\n"; print CGI::start_html(),"\n\n"; print CGI::start_table(); print CGI::Tr(CGI::th({-align => 'left'},['KEY','VALUE'])),"\n\n"; foreach my $key (sort keys %ENV ) { print CGI::Tr( CGI::td( {-align => 'left'},[$key ,$ENV{$key}])), +"\n"; } print CGI::end_table(),"\n\n"; print CGI::end_html();

      That way, the point is drilled in verbosely, to use CGI. :-)

      And incidentally, for posterity, it will come in handy to visit this link.


        I'd do it like this:
        #!/usr/bin/perl -w use CGI; my $q = new CGI; print $q->header, $q->start_html, $q->start_table; # etc
        Okay, so actually this requires more finger acrobatics, but at least it looks a lot better to me. But then, 'an old version of Perl' might very well mean Perl 4, which doesn't have OO. (But that's before my time, I believe I've just missed my first Perl anniversary ;-)
      I'm impressed! I tried developing on my laptop (Win2k with ISS) and uploading to linux/apache. DBI isn't cooperating yet, and Win32::ODBC -> DBI conversion after the fact is more trouble than it's worth (since most of my playing involves database operations). Someday I'll figure it out though, I hope.


        On Win32 you should try ADO datbase access (really fast).
        This makes converting most VB apps to Perl really easy.
        Since Perl supoports OLE try this:
        #!c:\perl\bin\perl -w use OLE; # create ADO auto object $conn = CreateObject OLE "ADODB.Connection" || die "CreateObject: $!"; # connect to data source $conn->Open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=accessDB.mdb +'); # query $sql = 'SELECT * FROM my_table_name'; # build recordset $rs = $conn->Execute($sql); # loop through recordset while(!$rs->EOF()) { print $rs->Fields('my_field_name')->Value; $rs->MoveNext(); } # shut down the recordset $rs->Close(); # close the data source $conn->Close();
Re: Perl & Personal Web Server
by dvergin (Monsignor) on Mar 02, 2001 at 05:03 UTC
    PWS can run Perl cgi scripts.

    How does PWS know where Perl is?
    On Windows 98 you need to make an entry in the Windows Registry. First make a back-up copy. Then fire up RegEdit and go to

    HKEY_LOCAL_MACHINE \System \CurrentControlSet \Services \W3SVC \Parameters \Script Map
    and add a new entry:    .pl = C:\Perl\bin\Perl %s %s
    ...or wherever Perl lives on your machine. I have seen the following entry recommended instead but I have not tried it:    .pl = C:\Perl\bin\PerlIS.dll
    In addition, I have read of a method that involves modifying the hash-bang line but I don't use that because I'd just have to change it before uploading to my server.

    The other thing you need to do is set up a cgi directory in PWS. Bring up the PWS admin window, click on Advanced, and then on Add... In the directory you set up, specify the Execute option. (You can have as many Execute directories as you want.)

    That should do it. Any more questions, just ask.

two other servers that run on win32 and support perl CGI
by howard40 (Beadle) on Mar 02, 2001 at 08:46 UTC
    ive never used PWS before, so i cant offer any information on how to configure it (however, every time i see PWS mentioned, it's usually a complaint about some ass-backwards way that it has to be configured)... i just wanted to drop a suggestion about two alternate (free and win32) servers that i thought you might want to try out and compare to PWS ;)

    apache now runs on win32 and (as far as i can tell) is just as stable as the unix variants. i have it running on my windows 2000 machine at home (along with activestate perl and php4) and i havent had a single problem with it yet....

    a lesser known win32 server is sambar. it's more limited than apache (doesnt support a lot of the interesting mod_* things that apache does), but it *does* support perl/CGI, and is great for testing of simple perl CGI sites. (i used to use sambar on my windows 95/98 machines before apache was stable enough on win32, and had no complaints)

    check them out... neither one of them requires you to go anywhere near regedit.exe ;)
Re: Perl & Personal Web Server
by zakzebrowski (Curate) on Mar 02, 2001 at 19:09 UTC
    In addition to pws and apache, another good web server (in my opinon) on windows machines is tiny web (free). In order to get the web server up and running and working with perl, unzip the exe's, make a root html directory (c:\mywebroot) and cgi-bin directory under root(C:\mywebroot\cgi-bin\), dump the .pl files in to the cgi-bin directory(C:\mywebroot\cgi-bin\, create a index.html in the root directory (C:\mywebroot\index.html)and type at the command line tiny c:\mywebroot\ (port) and you're off and running until you restart your computer. Works on 95,98,nt. (I assume me but I haven't tried it.)
Re: Perl & Personal Web Server
by Hot Pastrami (Monk) on Mar 02, 2001 at 04:26 UTC
    I may be wrong, but I don't _believe_ that PWS supports executing any kind of scripts... IIS will, but not PWS for Win 9x (to my knowledge). I'd suggest downloading Apache Webserver for Win32 and testing your site with it... it's free, easy to set up, and fully functional.

    Update: I was mistaken... there is a way, as described by dws below.

    Hot Pastrami

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://61692]
Approved by root
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-04-26 14:17 GMT
Find Nodes?
    Voting Booth?