Apache and Perl in Windows

Discussion in 'Perl Misc' started by Arn Anderson, Dec 23, 2005.

  1. Arn Anderson

    Arn Anderson Guest

    Hi and Merry Christmas. I am having a problem. The cgi scripts execute,
    but the output is empty. I am studying a spider book that uses Perl so I
    download perl and Apache, then uncomment out the lines in the web.xml
    file in apache and rename the jar files in the server directory. Then I
    launch apache and run my script using an HTML file. The script executes,
    but I don't see any results. Perl works fine separately and so does
    Apache. But together, they don't. Here is the source code for the 2
    files. I think this has to do with permissions, but when I installed
    Apache, I used the same account and password as my Windows username and I
    am administrator. I am out of ideas. If anyone knows what is going wrong,
    I would appreciate the help. Thank you.

    <HTML>
    <HEAD>
    <TITLE>Environment Variables
    using GET</TITLE>
    </HEAD>
    <BODY>
    <FORM ACTION="cgi-bin/exp.cgi" METHOD="GET">
    Press submit for a list of environment variables. <BR>

    First Name: <input type=
    "text" name="fname" size=
    30><p>
    Last Name: <input type="text"
    name="lname" size=30><p>
    <input type="submit">
    </form>

    <FORM>
    </BODY>
    </HTML>




    #!c:\Perl\bin\perl.exe
    use CGI qw:)all);
    use Strict;
    use LPW::Simple;

    print "Content-type: text/plain\n\n";

    foreach $var (sort keys %ENV) {
    print "$var=\"$ENV{$var}\"\n";
    }

    @values = split(/&/,$ENV{'QUERY_STRING'});
    foreach $i (@values) {
    ($varname, $mydata) = split(/=/,$i);
    print "$varname = $mydata\n";
    }
    Arn Anderson, Dec 23, 2005
    #1
    1. Advertising

  2. Arn Anderson

    Brian Wakem Guest

    Arn Anderson wrote:

    > Hi and Merry Christmas. I am having a problem. The cgi scripts execute,
    > but the output is empty. I am studying a spider book that uses Perl so I
    > download perl and Apache, then uncomment out the lines in the web.xml
    > file in apache and rename the jar files in the server directory. Then I
    > launch apache and run my script using an HTML file. The script executes,
    > but I don't see any results. Perl works fine separately and so does
    > Apache. But together, they don't. Here is the source code for the 2
    > files. I think this has to do with permissions, but when I installed
    > Apache, I used the same account and password as my Windows username and I
    > am administrator. I am out of ideas. If anyone knows what is going wrong,
    > I would appreciate the help. Thank you.
    >
    > <HTML>
    > <HEAD>
    > <TITLE>Environment Variables
    > using GET</TITLE>
    > </HEAD>
    > <BODY>
    > <FORM ACTION="cgi-bin/exp.cgi" METHOD="GET">
    > Press submit for a list of environment variables. <BR>
    >
    > First Name: <input type=
    > "text" name="fname" size=
    > 30><p>
    > Last Name: <input type="text"
    > name="lname" size=30><p>
    > <input type="submit">
    > </form>
    >
    > <FORM>
    > </BODY>
    > </HTML>
    >
    >
    >
    >
    > #!c:\Perl\bin\perl.exe
    > use CGI qw:)all);
    > use Strict;



    Should be lower case s.


    > use LPW::Simple;



    I don't believe this module exists, so your code does not compile.


    > print "Content-type: text/plain\n\n";



    Why use the CGI module and print your own headers?


    > foreach $var (sort keys %ENV) {



    Global symbol "$var" requires explicit package name at ....


    > print "$var=\"$ENV{$var}\"\n";
    > }
    >
    > @values = split(/&/,$ENV{'QUERY_STRING'});



    Global symbol "@var" requires explicit package name at ...

    There are many more errors. I can't be bothered to point them all out.
    Needless to say the code does not compile.


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
    Brian Wakem, Dec 23, 2005
    #2
    1. Advertising

  3. Arn Anderson

    Paul Lalli Guest

    Brian Wakem wrote:
    > > #!c:\Perl\bin\perl.exe
    > > use CGI qw:)all);
    > > use Strict;

    >
    > Should be lower case s.


    Should be, but Windows Perl won't complain about it. It also won't
    actually load the strict pragma. This is a completely meaningless and
    useless statement.

    > > foreach $var (sort keys %ENV) {

    >
    > Global symbol "$var" requires explicit package name at ....


    The OP wouldn't have gotten that error, because strict.pm is not
    actually loaded.

    > > @values = split(/&/,$ENV{'QUERY_STRING'});

    >
    > Global symbol "@var" requires explicit package name at ...


    Pretty sure you meant "@values", but again, the OP wouldn't have
    gotten this.

    > There are many more errors. I can't be bothered to point them all out.
    > Needless to say the code does not compile.


    With the LWP/LPW typo, I have to agree with this. The strict
    violations, however, do not prevent compilation.

    Paul Lalli
    Paul Lalli, Dec 23, 2005
    #3
  4. Arn Anderson

    Brian Wakem Guest

    Paul Lalli wrote:

    > Brian Wakem wrote:
    >> > #!c:\Perl\bin\perl.exe
    >> > use CGI qw:)all);
    >> > use Strict;

    >>
    >> Should be lower case s.

    >
    > Should be, but Windows Perl won't complain about it. It also won't
    > actually load the strict pragma.



    I see.



    >> > @values = split(/&/,$ENV{'QUERY_STRING'});

    >>
    >> Global symbol "@var" requires explicit package name at ...

    >
    > Pretty sure you meant "@values"



    Yes.



    >> There are many more errors. I can't be bothered to point them all out.
    >> Needless to say the code does not compile.

    >
    > With the LWP/LPW typo, I have to agree with this. The strict
    > violations, however, do not prevent compilation.



    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
    Brian Wakem, Dec 23, 2005
    #4
  5. Arn Anderson

    Arn Anderson Guest

    Thanks all for the posts. Here's one example that came straight from the
    Oreilly Spidering Hacks book that will not work in Windows with Apache. I
    have no clue as to why because it will work fine from the command line in
    ActiveState perl. And ActiveState has the LWP module already installed.
    Does ActiveState work better in IIS? I prefer Apache, but I've spent 2
    days just trying to figure this out. Is ActiveState the recommended
    version of Perl for Windows that you experts recommend?

    #!/usr/bin/perl -w (I replaced with #!c:\Perl\bin\perl.exe)
    use strict; (I removed this)
    use LWP::Simple; (I have use LWP::simple)


    # Just an example: the URL for the most recent /Fresh Air/ show
    my $url = 'http://freshair.npr.org/dayFA.cfm?todayDate=current';

    my $content = get($url);
    die "Couldn't get $url" unless defined $content;

    # Do things with $content:
    if ($content =~ m/jazz/i) {
    print "They're talking about jazz today on Fresh Air!\n";
    } else { print "Fresh Air is apparently jazzless today.\n"; }
    Arn Anderson, Dec 23, 2005
    #5
  6. Arn Anderson

    Guest

    Arn Anderson wrote:
    > Thanks all for the posts. Here's one example that came straight from the
    > Oreilly Spidering Hacks book that will not work in Windows with Apache. I
    > have no clue as to why because it will work fine from the command line in
    > ActiveState perl. And ActiveState has the LWP module already installed.
    > Does ActiveState work better in IIS? I prefer Apache, but I've spent 2
    > days just trying to figure this out. Is ActiveState the recommended
    > version of Perl for Windows that you experts recommend?
    >
    > #!/usr/bin/perl -w (I replaced with #!c:\Perl\bin\perl.exe)
    > use strict; (I removed this)
    > use LWP::Simple; (I have use LWP::simple)
    >
    >
    > # Just an example: the URL for the most recent /Fresh Air/ show
    > my $url = 'http://freshair.npr.org/dayFA.cfm?todayDate=current';
    >
    > my $content = get($url);
    > die "Couldn't get $url" unless defined $content;
    >
    > # Do things with $content:
    > if ($content =~ m/jazz/i) {
    > print "They're talking about jazz today on Fresh Air!\n";
    > } else { print "Fresh Air is apparently jazzless today.\n"; }


    Have you checked the Apache error logs..., ensured the headers are
    correct?
    checked CGI FAQ's...? Try 'perldoc -q cgi' for a list of pointers,
    URL's and
    helpful tips if you haven't already.

    If you still can't resolve the problem, the heavier duty LWP modules
    may
    need to be used to pinpoint the problem, eg. See 'Hack #10. More
    involved
    Requests with LWP::UserAgent ' in 'Spidering Hacks'.

    hth,
    --
    Charles DeRykus
    , Dec 24, 2005
    #6
  7. Arn Anderson

    Arn Anderson Guest

    I have not been able to resolve this problem, but as a note to future
    programmers who might run into this problem, Perl from ActiveState simply
    is not very compatible with Apache. Here is the code I ran in IIS and
    Apache. Both used the same perl. Only difference is that Apache shows no
    results while IIS printed out "Fresh Air is apparently jazzless today.
    \n". If anyone has an answer to why IIS works and Apache does not, I
    would be interested to know. But for now, I will have to use IIS.


    #!c:\Perl\bin\perl.exe
    use LWP 5.64;

    print "Content-type: text/plain\n\n";

    $url = 'http://freshair.npr.org/dayFA.cfm?todayDate=current';

    $browser = LWP::UserAgent->new;
    $response = $browser->get( $url );

    die "Can't get $url -- ", $response->status_line
    unless $response->is_success;

    die "Hey, I was expecting HTML, not ", $response->content_type
    unless $response->content_type eq 'text/html';

    if ($response->content =~ m/jazz/i) {
    print "They're talking about jazz today on Fresh Air!\n";
    } else {
    print "Fresh Air is apparently jazzless today.\n";
    }
    Arn Anderson, Dec 24, 2005
    #7
  8. Arn Anderson

    Arn Anderson Guest

    "" <> wrote in
    news::

    >
    > Arn Anderson wrote:
    >> Thanks all for the posts. Here's one example that came straight from
    >> the Oreilly Spidering Hacks book that will not work in Windows with
    >> Apache. I have no clue as to why because it will work fine from the
    >> command line in ActiveState perl. And ActiveState has the LWP module
    >> already installed. Does ActiveState work better in IIS? I prefer
    >> Apache, but I've spent 2 days just trying to figure this out. Is
    >> ActiveState the recommended version of Perl for Windows that you
    >> experts recommend?
    >>
    >> #!/usr/bin/perl -w (I replaced with
    >> #!c:\Perl\bin\perl.exe) use strict; (I removed
    >> this) use LWP::Simple; (I have use LWP::simple)
    >>
    >>
    >> # Just an example: the URL for the most recent /Fresh Air/ show
    >> my $url = 'http://freshair.npr.org/dayFA.cfm?todayDate=current';
    >>
    >> my $content = get($url);
    >> die "Couldn't get $url" unless defined $content;
    >>
    >> # Do things with $content:
    >> if ($content =~ m/jazz/i) {
    >> print "They're talking about jazz today on Fresh Air!\n";
    >> } else { print "Fresh Air is apparently jazzless today.\n"; }

    >
    > Have you checked the Apache error logs..., ensured the headers are
    > correct?
    > checked CGI FAQ's...? Try 'perldoc -q cgi' for a list of pointers,
    > URL's and
    > helpful tips if you haven't already.
    >
    > If you still can't resolve the problem, the heavier duty LWP modules
    > may
    > need to be used to pinpoint the problem, eg. See 'Hack #10. More
    > involved
    > Requests with LWP::UserAgent ' in 'Spidering Hacks'.
    >
    > hth,
    > --
    > Charles DeRykus
    >


    Thanks. I did check the log file in Apache and nothing shows up. I
    believe the problem could be with the fact that Apache is calling perl
    using some sort of "execute program" method in Java and Windows 2000 does
    not like this for some reason. But I guess IIS allows this because I
    checked on the box in IIS to allow cgi scripts to execute programs in
    Windows. Just a hunch.
    Arn Anderson, Dec 24, 2005
    #8
  9. Arn Anderson <> wrote in news::

    > #!/usr/bin/perl -w (I replaced with #!c:\Perl\bin\perl.exe)


    Why?

    > use strict; (I removed this)


    Why?

    > use LWP::Simple; (I have use LWP::simple)


    Why?


    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Dec 24, 2005
    #9
  10. A. Sinan Unur, Dec 24, 2005
    #10
  11. Arn Anderson

    Scott Bryce Guest

    Arn Anderson wrote:
    > Perl from ActiveState simply is not very compatible with Apache.


    Your script works fine for me run as a CGI script on my machine.

    Apache 2.0.48
    ActiveState Perl 5.8.2
    Windows 98SE
    Scott Bryce, Dec 24, 2005
    #11
  12. Arn Anderson

    Todd W Guest

    "Arn Anderson" <> wrote in message
    news:...
    > I have not been able to resolve this problem, but as a note to future
    > programmers who might run into this problem, Perl from ActiveState simply
    > is not very compatible with Apache.


    <snip>

    This is not true. On a properly configured system Apache and ActiveState
    perl work absolutely fine together.

    Todd W.
    Todd W, Dec 24, 2005
    #12
  13. Arn Anderson

    Henry Law Guest

    A. Sinan Unur wrote:
    > Arn Anderson <> wrote in news::
    >
    >
    >>#!/usr/bin/perl -w (I replaced with #!c:\Perl\bin\perl.exe)

    >
    >
    > Why?


    Apache under Windows checks the shebang line and if it's not valid emits
    a not-terribly-informative "The system cannot find the path specified.
    : couldn't spawn child process: ..." message. I spent a very
    frustrating afternoon a week or two back debugging this one.
    Henry Law, Dec 24, 2005
    #13
  14. Henry Law <> wrote in news::

    > A. Sinan Unur wrote:
    >> Arn Anderson <> wrote in news::
    >>
    >>
    >>>#!/usr/bin/perl -w (I replaced with #!c:\Perl\bin\perl.exe)

    >>
    >>
    >> Why?

    >
    > Apache under Windows checks the shebang line and if it's not valid emits
    > a not-terribly-informative "The system cannot find the path specified.
    >: couldn't spawn child process: ..." message. I spent a very
    > frustrating afternoon a week or two back debugging this one.


    Hmmm ... See:

    <URL:http://httpd.apache.org/docs/2.0/mod/core.html#scriptinterpretersource>

    <URL:http://groups.google.com/group/comp.lang.perl.misc/msg/2c41b461d98a586b>

    <URL:http://groups.google.com/group/comp.lang.perl.misc/msg/2ba2cd005a3cf1f7>

    Sinan


    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Dec 24, 2005
    #14
  15. Arn Anderson

    Henry Law Guest

    A. Sinan Unur wrote:
    > Henry Law <> wrote in news::


    >>Apache under Windows checks the shebang line and if it's not valid emits

    > Hmmm ... See:
    >
    > <URL:http://httpd.apache.org/docs/2.0/mod/core.html#scriptinterpretersource>

    .... etc
    > Sinan


    Whereas A. Sinan Unur could with trivially extra effort have written

    > Yes, by default, but see ... etc


    Your "Hmmm" drips disapproval.
    Henry Law, Dec 24, 2005
    #15
  16. Henry Law <> wrote in
    news::

    > A. Sinan Unur wrote:
    >> Henry Law <> wrote in
    >> news::

    >
    >>>Apache under Windows checks the shebang line and if it's not valid
    >>>emits

    >> Hmmm ... See:
    >>
    >>

    <URL:http://httpd.apache.org/docs/2.0/mod/core.html#scriptinterpreters
    >> ource>

    > ... etc
    >> Sinan

    >
    > Whereas A. Sinan Unur could with trivially extra effort have written
    >
    > > Yes, by default, but see ... etc

    >
    > Your "Hmmm" drips disapproval.


    Of course, it does, since you could have, yourself, trivially, with
    little extra effort, searched the archives of this newsgroup, or read
    the Apache documentation, to find out why one need not change shebang
    lines to run Perl scripts under Apache for Windows.

    Or, you could have, easily, trivially, with little extra effort, say
    "oh, I did not know that, my assertion was unfounded", thanked for the
    pointers, and moved on.

    Oh well.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Dec 27, 2005
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page