Perl
How do I use ActivePerl under Apache

If you want to put all of your CGI scripts into one directory, add the following line to your srm.conf file (You can choose any directory you'd like, but make sure it exists):

    ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/"

After you have made this change, stop and restart the Apache service.

Apache provides an emulation of the UNIX shebang (#!/path/to/perl) syntax, so the next step is easy. You can put you Perl scripts into your cgi-bin directory, as long as you have a path to a valid interpreter at the top. For example:

    #!C:\PERL\5.00464\bin\MSWin32-x86\perl.exe
     
    use CGI qw(:standard) ;
    print header();
    print "Hello, world";

If you want to enable CGI scripts based on an extension, such as .pl, you need to add the following line to srm.conf:

    AddHandler cgi-script .pl

By default, CGI scripts are not allowed in your DocumentRoot directory, but they are allowed in other document directories. Document directories are created with the Alias command in srm.conf:

    Alias /ResourceKit/ "E:/utilsamp/"

You can then include files that end in .pl within a document directory. You will still need to include the #! line with the full path to the perl.exe interpreter, as shown earlier.

If you want to allow CGI scripts in the DocumentRoot directory, add the ExecCGI option to the Options directive between the <Directory> and </Directory> entry for your DocumentRoot in access.conf (these appear directly after the comment titled:

    # This should be changed to whatever you set DocumentRoot to.
    
After you have updated it, your Options directive may look something like:
 Options Indexes FollowSymLinks ExecCGI
How do I configure Microsoft IIS 4.0 to support ActivePerl

Microsoft IIS 4.0 ships with Windows NT Server 5.0, and PWS 4.0 ships with Windows NT Workstation 5.0. Both IIS and PWS are available as part of the Microsoft Windows NT 4.0 Option Pack. You can find a link to the Option Pack at http://www.microsoft.com/iis/

To configure IIS or PWS 4.0 to run Perl scripts:

  1. Open the IIS 4.0 Internet Service Manager. This will bring up the Microsoft Management Console with the Internet Service Manager snap-in selected.

  2. From the tree display on the left, select the level at which to apply the mappings. You can choose an entire server, web site, or a given virtual directory.

  3. Select Properties from the Action menu.

  4. If you chose to administer the properties for the entire server, the Server Properties dialog will appear. Select WWW Service from the Master Properties pull-down menu and click the Edit button under Master Properties. This opens WWW Service Master Properties. Select the Home Directory tab and proceed to step 7.

  5. If you chose to administer the properties for an entire web site, the Web Site Properties sheet appears. Select the Home Directory tab and proceed to step 7.

  6. If you chose to administer the properties for a virtual directory, the Virtual Directory Properties sheet appears. Select the Virtual Directory tab and proceed to step 7.

  7. Click the Configuration button. This opens the Application Configuration dialog.

  8. Select the App Mappings tab and click the Add button. You see the Add/Edit Application Extension Mapping dialog.

  9. To run Perl as a CGI application, type the full path to Perl.EXE followed by %s %s. When a script is executed, the first %s will be replaced by the full path to the script, and the second %s will be replaced by the script parameters.

  10. To run Perl for ISAPI, type the full path to PerlIS.DLL. The %s %s is not required for ISAPI DLLs.

  11. In the Extension field, type .pl or .plx (or whatever extension you want to use).

  12. The application mapping is now complete. Click the OK button and click OK to dismiss any remaining dialogs/property sheets.

  13. Close the IIS 4.0 Internet Service Manager.

Because IIS runs as a service (see What is a Windows NT service?), you need to take special steps to make sure that files and environment variables are available to it.

My Sql
#!/usr/bin/perl
print "Content-Type: text/html\n\n";

# Use the DBI module
use DBI qw(:sql_types);

# Declare local variables
my ($databaseName, $databaseUser, $databasePw, $dbh);
my ($stmt, $sth, @record);
my ($telephone);

print "start\n";

# Set the parameter values for the connection
$databaseName = "DBI:mysql:mybase_com";
$databaseUser = "USERLOGIN";
$databasePw = "USERPASSWORD";

$dbh = DBI->connect($databaseName, $databaseUser, $databasePw) || die "Connect failed: $DBI::errstr\n";
print "connect\n";

$stmt = "SELECT phone FROM mybasefile"; 
$sth = $dbh->prepare($stmt) || die "prepare: $stmt: $DBI::errstr";
print "prepare\n";
$sth->execute || die "execute: $stmt: $DBI::errstr";
print "execute\n";

@record = $sth->fetchrow();

$telephone = $record[0];

print $telephone;
$sth->finish();

$dbh->disconnect();

Hosted by uCoz