Problem getting started

View: New views
7 Messages — Rating Filter:   Alert me  

Problem getting started

by John M. Dlugosz-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm trying to use mod_perl on Debian Etch.  I was looking at "practical mod_perl" book, but it appears that much has changed in mod_perl 2.0 so the second example doesn't work at all.

The first example, which is just two print statements to give a minimal header and content text, is invoked so I know the code is installed and the Apache configuration files are set up.

But the code from the Synopses of the Apache2::Request module documentation causes a segfault on the second line.  The 'use' is OK, but the 'new' shows in the apache logs that there was a segfault.

How do I begin to find out what the real error is?  Is there something more that needs to be done with Debian installing from the apt?  Could someone post a trivial example that ought to work?

--John

Re: Problem getting started

by adam.prime :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John M. Dlugosz wrote:
> I'm trying to use mod_perl on Debian Etch.  I was looking at "practical mod_perl" book, but it appears that much has changed in mod_perl 2.0 so the second example doesn't work at all.
>
> The first example, which is just two print statements to give a minimal header and content text, is invoked so I know the code is installed and the Apache configuration files are set up.
>
> But the code from the Synopses of the Apache2::Request module documentation causes a segfault on the second line.  The 'use' is OK, but the 'new' shows in the apache logs that there was a segfault.
>
> How do I begin to find out what the real error is?  Is there something more that needs to be done with Debian installing from the apt?  Could someone post a trivial example that ought to work?
>
> --John

It looks like the examples from practical mod_perl are from before the
API was changed to use Apache2:: instead of Apache::.  So for all those
examples you'd need to s/Apache::/Apache2::/g.  If you could provide a
link to the specific example you're having trouble with that might help.
   The whole book is online at http://modperlbook.org/ if you weren't
already aware.

For the Apache2::Request problem you're running:

     use Apache2::Request;
     $req = Apache2::Request->new($r);
     @foo = $req->param("foo");
     $bar = $req->args("bar");

and getting a segfault on new?

Are you running this as a handler, or through one of the CGI emulation
layers (ModPerl::PerlRun, or ModPerl::Registry for example).  you do
also have

my $r = shift;

somewhere above that (and ideally use strict; as well) right?

I personally normally install mp and libapreq from source, so i'm not
familiar with how one would install/configure them using debian.

Adam

Re: Problem getting started

by Raymond Wan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi John,

Unfortunately, I'm still muddy with modperl to help you even though I'm
on Debian Etch.   I have it working and can tell you what I have
installed...but I can't help you with modperl specifics as I'll probably
end up teaching the wrong thing.

To answer Adam's question:


Adam Prime wrote:
> John M. Dlugosz wrote:
>> I'm trying to use mod_perl on Debian Etch.  I was looking at
>> "practical mod_perl" book, but it appears that much has changed in
>> mod_perl 2.0 so the second example doesn't work at all.
>>
> I personally normally install mp and libapreq from source, so i'm not
> familiar with how one would install/configure them using debian.

aptitude install libapreq2

as root (or sudo).  Or just install everything related if you are not sure:

aptitude install libapache2-mod-apreq2 libapreq2 libapreq2-dev libapreq2-doc

(I have all of them installed.)

Of course, apt-get works too, if you prefer that.  I don't remember
doing more configuration.  There's a symlink from
/etc/apache2/mods-enabled/apreq.load to
/etc/apache2/mods-available/apreq.load

Sorry, can't think of anything else tricky that I did.  I hope this is
enough.

Ray





Parent Message unknown Re: Problem getting started

by adam.prime :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Please include the list on replies, so the archives are complete.

Quoting "John M. Dlugosz" <l3hc4oo02@...>:

> Adam Prime adam.prime-at-utoronto.ca |mod_perl mailing list| wrote:
>> For the Apache2::Request problem you're running:
>>
>>    use Apache2::Request;
>>    $req = Apache2::Request->new($r);
>>    @foo = $req->param("foo");
>>    $bar = $req->args("bar");
>>
>> and getting a segfault on new?
>
> If I reduce it down to the first two lines only, I get the segfault.
> If I reduce it to the first line only, I don't.
>
>
>> Are you running this as a handler, or through one of the CGI    
>> emulation layers (ModPerl::PerlRun, or ModPerl::Registry for    
>> example).  you do
>
> ModPerl::Registry.
>
> In my apache2.conf file:
>
> PerlModule ModPerl::Registry
>
> <Location "/modperl/">
>    SetHandler perl-script
>    PerlHandler ModPerl::Registry
>    Options +ExecCGI
>    PerlSendHeader On
>    Allow from all
> </Location>
>
> Hmm, is there a way to find out whether these settings are applying to
> the directory I think it is?  /modperl/ should be applied to each
> DocumentRoot, right?
>

correct.

>> also have
>>
>> my $r = shift;
>>
>> somewhere above that (and ideally use strict; as well) right?
>
> No, just what it shows in the example.

This is your problem.  Apparently if you call Apache2::Request->new
with an undefined object, it segfaults.

i ran this:

use Apache2::Request;
my $req = Apache2::Request->new($r);
print qq[Content-type: text/html\n\n];
print q[hi];

through registry, and saw

[Sat Jul 12 22:58:58 2008] [notice] child pid 5703 exit signal
Segmentation fault (11)

If you change that to

use Apache2::Request;
my $r = shift;
my $req = Apache2::Request->new($r);
print qq[Content-type: text/html\n\n];
print q[hi];

it should work.  Unfortunately, it looks like the documentation for
ModPerl::Registry is kind of lacking on perl.apache.org, but what is
there is at
http://perl.apache.org/docs/2.0/api/ModPerl/Registry.html

Adam





Re: Problem getting started

by John M. Dlugosz-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> This is your problem.  Apparently if you call Apache2::Request->new
> with an undefined object, it segfaults.
>
> i ran this:
>
> use Apache2::Request;
> my $req = Apache2::Request->new($r);
> print qq[Content-type: text/html\n\n];
> print q[hi];
>
> through registry, and saw
>
> [Sat Jul 12 22:58:58 2008] [notice] child pid 5703 exit signal
> Segmentation fault (11)
>
> If you change that to
>
> use Apache2::Request;
> my $r = shift;
> my $req = Apache2::Request->new($r);
> print qq[Content-type: text/html\n\n];
> print q[hi];
>
> it should work.  Unfortunately, it looks like the documentation for
> ModPerl::Registry is kind of lacking on perl.apache.org, but what is
> there is at
> http://perl.apache.org/docs/2.0/api/ModPerl/Registry.html
>
> Adam
>
OK, when I defined $r as you did, it worked.  For documentation, I was
looking at here:
<http://search.cpan.org/~joesuf/libapreq2-2.08/glue/perl/lib/Apache2/Request.pm>

I see you are just printing to standard output, like a CGI script.  In
the book, it used

    $r->send_http_header('text/plain');
    $r->print("mod_perl rules!\n");

but there are no such methods on $r here in 2.0.

What, prey tell, is the equivalent object?

Is there =any= way to get started, like a simple (but working!) program
I could look at?

--John


Re: Problem getting started

by Raymond Wan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi John,


John M. Dlugosz wrote:

> OK, when I defined $r as you did, it worked.  For documentation, I was
> looking at here:
> <http://search.cpan.org/~joesuf/libapreq2-2.08/glue/perl/lib/Apache2/Request.pm>
>
>
> I see you are just printing to standard output, like a CGI script.  In
> the book, it used
>
>    $r->send_http_header('text/plain');
>    $r->print("mod_perl rules!\n");
>
> but there are no such methods on $r here in 2.0.
>
> What, prey tell, is the equivalent object?
> Is there =any= way to get started, like a simple (but working!)
> program I could look at?


When I was starting with modperl2, I had similar problems to you.  I'm
more of a book-person, and many of the books (such as the O'Reilly ones)
have not been re-released for modperl2.  While there is a lot of
information on the web, it isn't as easy sifting through it all.

As for your question, the $r object is (I believe :-) ) the RequestRec
object:

http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html

and instead of send_http_header, you would use content_type.  As
mentioned here which describes porting mod_perl 1.0 to mod_perl 2.0:

http://perl.apache.org/docs/2.0/user/porting/compat.html#C__r_E_gt_send_http_header_

You may need to use these two documents (at least) in conjunction with
the book you are reading to make any sense of it.  Hope this helps!

Ray




Re: Problem getting started

by Perrin Harkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Jul 13, 2008 at 1:21 AM, John M. Dlugosz
<l3hc4oo02@...> wrote:
> OK, when I defined $r as you did, it worked.  For documentation, I was
> looking at here:
> <http://search.cpan.org/~joesuf/libapreq2-2.08/glue/perl/lib/Apache2/Request.pm>

Hi John,

That SYNOPSIS is more like a set of possible calls to
Apache2::Request, not a literal series of lines.  You do need to get
$r (an Apache2::RequestRec object) first.

> I see you are just printing to standard output, like a CGI script.

When using ModPerl::Registry, you can just print to STDOUT.

> In the book, it used
>
>   $r->send_http_header('text/plain');
>   $r->print("mod_perl rules!\n");
>
> but there are no such methods on $r here in 2.0.
>
> What, prey tell, is the equivalent object?

That's Apache2::RequestRec.

> Is there =any= way to get started, like a simple (but working!) program I
> could look at?

There are two places you should look for MP2 docs.  The first is the
mod_perl site, which has all the API docs and many examples.  If you
want a book, the only one you should use for MP2 at this point is
"mod_perl2 User's Guide": http://modperl2book.org/

- Perrin