daveklingler has asked for the wisdom of the Perl Monks concerning the following question:

I've been trying to figure out how to use Apache2::Request/RequestRec/Upload for the past couple of days and I've run into an interesting mod_perl problem. Tonight after a lot of struggle I thought of pasting a code snippet from the Apache.org website:

use Apache2::Upload; $req = Apache2::Request->new($r); $upload = $req->upload("foo"); $size = $upload->size; # three methods to get at the upload's contents ... slurp, fh, io $upload->slurp($slurp_data); read $upload->fh, $fh_data, $size; ok $slurp_data eq $fh_data; my $io = $upload->io; print while <$io>;

Unfortunately while I would have sworn it ran when I first tried it, I'm now getting a 500 Internal Server Error and the following in my log (no matter what test scripts I run, not just this one):

[Wed Sep 16 22:23:32 2009] [error] [client ::1] dyld: lazy symbol bind +ing failed: Symbol not found: _modperl_xs_sv2request_rec [Wed Sep 16 22:23:32 2009] [error] [client ::1] Referenced from: /Li +brary/Perl/5.8.8/darwin-thread-multi-2level/auto/APR/Request/Apache2/ +Apache2.bundle [Wed Sep 16 22:23:32 2009] [error] [client ::1] Expected in: dynamic + lookup [Wed Sep 16 22:23:32 2009] [error] [client ::1] [Wed Sep 16 22:23:32 2009] [error] [client ::1] dyld: Symbol not found +: _modperl_xs_sv2request_rec [Wed Sep 16 22:23:32 2009] [error] [client ::1] Referenced from: /Li +brary/Perl/5.8.8/darwin-thread-multi-2level/auto/APR/Request/Apache2/ +Apache2.bundle [Wed Sep 16 22:23:32 2009] [error] [client ::1] Expected in: dynamic + lookup [Wed Sep 16 22:23:32 2009] [error] [client ::1] [Wed Sep 16 22:23:32 2009] [error] [client ::1] Premature end of scrip +t headers: test.cgi

Can anyone tell me what I'm missing? Make test ran 100% okay, and my httpd.conf does include "LoadModule perl_module modules/mod_perl.so" and "LoadModule apreq_module modules/mod_apreq2.so".

Many thanks!

Replies are listed 'Best First'.
Re: mod_perl lib problem
by cmac (Monk) on Sep 17, 2009 at 06:46 UTC
    Does the modules directory in your Apache2 directory in fact contain mod_perl.so and mod_apreq2.so?

    Did you install Bundle::Apache2? If not,
    perl -MCPAN -e "install Bundle::Apache2"

    Where did you put the code snippet you cite, and how did you invoke it?

    Best thing to do would be to get a copy of "mod_perl2 User's Guide" by Stas Bekman and Jim Brandt:
    http://www.amazon.com/gp/offer-listing/0977920119/ref=dp_olp_used?ie=UTF8&qid=1253169502&sr=1-1&condition=used

    cmac
      Hi cmac. Thanks very much for your reply.

      The modules directory does in fact contain mod_perl.so and mod_apreq2.so.

      I had not installed Bundle::Apache2. I did so, but the situation did not change.

      The code snippet was placed in cgi-bin, and invoked as http://localhost/cgi-bin/test.cgi. The full file contents are:

      -------------------------------------------------------- #!/usr/bin/perl use Apache2::Upload; $req = Apache2::Request->new($r); $upload = $req->upload("foo"); $size = $upload->size; # three methods to get at the upload's contents ... slurp, fh, io $upload->slurp($slurp_data); read $upload->fh, $fh_data, $size; ok $slurp_data eq $fh_data; my $io = $upload->io; print while <$io>; --------------------------------------------------------
      voronwae
        After adding the LoadModules to your httpd.conf file, you should have restarted Apache. The output from that will be in your error_log file, before the error messages that you posted originally. What does the signature line (the last output line from the restart) say?

        Upload seems a strange place to start your adventures with mod_perl, but probably that's what you're interested in. Most people would start with a small script that just output an HTML or text page (or using a CGI program that they already have). Then you can branch out into uploading.

        Typically, one adds several more things to httpd.conf in addition to the LoadModule lines. If you're don't want to get the recommended book, try the following page and click on the "Server Configuration" link: http://perl.apache.org/docs/2.0/user/index.html In particular you need to create a directory to hold mod_perl scripts, and move your script into it. Then you need to put a Location block in httpd.conf that sets the new directory up to use mod_perl, as described in the linked page.

        Where on the Apache site did you get the code snippet?

        cmac

        I thought perhaps I'd post this:

        sh-3.2# /usr/local/apache2/bin/httpd -M Loaded Modules: core_module (static) authn_file_module (static) authn_default_module (static) authz_host_module (static) authz_groupfile_module (static) authz_user_module (static) authz_default_module (static) auth_basic_module (static) include_module (static) filter_module (static) log_config_module (static) env_module (static) setenvif_module (static) mpm_prefork_module (static) http_module (static) mime_module (static) status_module (static) autoindex_module (static) asis_module (static) cgi_module (static) negotiation_module (static) dir_module (static) actions_module (static) userdir_module (static) alias_module (static) so_module (static) php5_module (shared) perl_module (shared) apreq_module (shared) Syntax OK