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

here is my problem:

I cannot, simply *cannot*, get connect_on_init to run on my mod_perl -> SQL database. (Apache 2.0.52)

here's the project's life story:
1. have perl script hit by many users.
2. want to 'precompile it'.
3. fix it up for mod_perl.
4. enable mod_perl (1.9916) on server, run it in mod perl.
5. Apache::DBI into the httpd.conf.
5b. code starts not being able to connect to DB every onece in a while.
6. "hey, you should have connect_on_init in your startup file!"
7. "Apache.pm was not loaded at startup.pl line 28".

And there we are. Nothing I've tried has gotten this to work, and I've been hacking at it for *days*.

Now, old perlmonks threads have said to upgrade to modperl2, but Apache::DBI "has only been tested "very lightly". and it would also require the Apache2::compat module. So I'm wary.

QUESTION: Should I upgrade? if so, what should I expect? the only thing my server uses on mod_perl now is a test file, the rest is all CGI. If there is an easy fix (to the 'get dbi to connect' issue), I'd rather not upgrade, just for ease of implementation.

I'm right here at console, so if anyone can help, maybe "hey Mash, have you tried this?", you'd be a lifesaver. Thanks in advance.

update: startup code:
#!/usr/local/bin/perl -w $ENV{MOD_PERL} or die "GATEWAY_INTERFACE not Perl!"; use Apache::DBI; use strict; Apache::DBI->connect_on_init('DBI:mysql:database=dbname;host=localhost +','dbuser','',{ PrintError => 1, RaiseError => 0, AutoCommit => 1}); +### THIS IS LINE 28 WITH NAMES / PWDS TAKEN OUT Apache::DBI->setPingTimeOut('DBI:mysql:dbname', 0); 1;
I don't want to update, but, getting this Apache::DBI to work seems impossible where I'm at. If I'm missing something, neither I nor my server techs can find it..
  • Comment on Apache::DBI "cannot find apache.pm" failure - Should I upgrade from mod_perl 1.0 to 2.0? and if so, how?
  • Download Code

Replies are listed 'Best First'.
Re: Should I upgrade from mod_perl 1.0 to 2.0? and if so, how?
by Corion (Patriarch) on Feb 17, 2009 at 14:42 UTC

    You can help us help you better by showing us startup.pl, especially the line 28, which fails. I don't think upgrading mod_perl to 2.0 is a solution for everything, since mod_perl 2 is different from mod_perl 1 in many situations.

      Whoops, sorry, meant to put that in:
      #!/usr/local/bin/perl -w $ENV{MOD_PERL} or die "GATEWAY_INTERFACE not Perl!"; use Apache::DBI; use strict; Apache::DBI->connect_on_init('DBI:mysql:database=dbname;host=localhost +','dbuser','',{ PrintError => 1, RaiseError => 0, AutoCommit => 1}); +### THIS IS LINE 28 WITH NAMES / PWDS TAKEN OUT Apache::DBI->setPingTimeOut('DBI:mysql:dbname', 0); 1;

        From looking at the Apache::DBI source code, the error message Apache.pm was not loaded is raised if it doesn't detect a true value in $INC{'Apache.pm'}. This indicates to me that you're not running your script under mod_perl at all, or (really remote) that Apache.pm fails to load. Maybe put use Apache; into your main script, just for a test.

Re: Apache::DBI "cannot find apache.pm" failure - Should I upgrade from mod_perl 1.0 to 2.0? and if so, how?
by moritz (Cardinal) on Feb 17, 2009 at 14:55 UTC
    If it says "Apache.pm was not loaded at startup.pl line 28", the question arises: Did you load Apache.pm? And if not, why not?
      I didn't, because the 'here is your first startup.pl' didn't have it in, it just says to uncomment the connect_on_init line.

      Having done so, (use Apache;) I get a 'not found in @INC' error. am I missing an install? what would the bundle name be on CPAN?
        I'm using Debian Linux, and on my system Apache.pm comes bundled with libapache-mod-perl. Maybe you can also find it in the Apache packages somewhere?
Re: Apache::DBI "cannot find apache.pm" failure - Should I upgrade from mod_perl 1.0 to 2.0? and if so, how?
by perrin (Chancellor) on Feb 17, 2009 at 14:59 UTC
    Do not run mod_perl 1.9*!!! It's 4 years old and BROKEN BROKEN BROKEN! Use the current version and your problems will go away.
      That's what I hear. My server people, though, only support redhat, and 1.99 was the last one in that. plus, some people here said that 1.0 might still be fine.

      If I wanted to, though, how would I go about getting mod_perl 2.X up and running on this? CPAN just says I'm up to date when I try to get 'mod_perl'.
        The deal is, you are running alpha software that Red Hat should never have packaged. The whole 1.9* line is a pre-release of 2.0 and it no longer works. That's why you can't get this to go. Apache::DBI works with 2.*, so get a recent version. I do recommend using the latest source and making an RPM from your own build, but if you have to use an external RPM try to find a source RPM from a more recent Red Hat release that you can recompile for your platform.