Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Perl & Personal Web Server

by dws (Chancellor)
on Mar 02, 2001 at 04:58 UTC ( #61720=note: print w/ replies, xml ) Need Help??


in reply to Perl & Personal Web Server

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).
  2. Open HKEY_LOCAL_MACHINE
  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";


Comment on Re: Perl & Personal Web Server
Select or Download Code
Re: Re: Perl & Personal Web Server
by mkmcconn (Chaplain) on Mar 02, 2001 at 07:10 UTC
    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.

    mkmcconn

      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 ;-)

        Of course it looks much better that way, orkysoft. Not to take any points away from beauty, the point was be 'verbose' in reminding beginners to 'use CGI'.

        A bit of (I'd hoped) useful (but dubitable) humor, you see. :-)
        mkmcconn

Re: Re: Perl & Personal Web Server
by Lexicon (Chaplain) on Mar 02, 2001 at 14:50 UTC
    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.

    -Lexicon

      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();

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://61720]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (19)
As of 2014-07-29 16:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (222 votes), past polls