You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Boysenberry Payne <bo...@humaniteque.com> on 2005/02/06 07:09:11 UTC

Need help getting DBI to work under mod_perl

I'm able to run DBI->connect() fine when I run my .pl and .pm scripts 
as mod_cgi.
Once I set up my httpd.conf and startup.pl files it no longer works.  I 
get the following:

Can't connect to MySQL server on 'localhost' (49)

I can't find what (49) means anywhere...

I've included my code below, maybe I'm missing something particular to 
mod_perl.
Again, all of the code has worked for both mod_cgi and as a stand alone 
using
perl updater.pl.  (obviously, I changed the print statements as well as 
some of the
complexities surrounding the original intentions for the script.)

I running Mac OS X darwin, and get everything as showing correctly in 
the %ENV.

I'm stumped, been looking high and low for a couple of days...



I set httpd.conf up using the following:

Alias /perl/ "/Users/WebRoot/perl/"

PerlWarn On
PerlTaintCheck On

<Directory "/Users/WebRoot/perl">
	AllowOverride None
	SetHandler perl-script
	PerlHandler Apache::Registry
	PerlSendHeader On
	Options ExecCGI Indexes FollowSymlinks
	Order allow,deny
	Allow from all
</Directory>

PerlRequire /etc/httpd/perl/startup.pl
PerlFreshRestart On

and in my startup.pl:

#!/usr/bin/perl
use strict;

BEGIN {
   use Apache();
   $ENV{ MOD_PERL } or die "not running under mod_perl!";
}
use Apache::Registry();
use Apache::Constants();
use CGI();
CGI->compile();
use CGI::Carp();
use Carp();
use DBI();
1;

and in my updater.pl script:

#!/usr/bin/perl -w
use DBI;

use strict;
use warnings;

my $r = Apache->request;
$r->print( header() );
$r->print( start_html( "My Perl Updater" ) );
my $dsn = "DBI:mysql:database=test";
my $test_db = eval{ DBI->connect( $dsn, "...", "...", { RaiseError => 
1, PrintError => 1, AutoCommit => 1 } ) };
$r->print( $DBI::lasth->errstr );
$r->print( end_html() );

Re: Need help getting DBI to work under mod_perl

Posted by Boysenberry Payne <bo...@humaniteque.com>.
It's localhost, and I did.  I'm developing on a local environment.
On Feb 6, 2005, at 8:24 AM, Tom Schindl wrote:

> Give it a try and add the hostname you are connecting to to the DSN.
>
> Tom
> Boysenberry Payne wrote:
>
>> I'm able to run DBI->connect() fine when I run my .pl and .pm scripts 
>> as mod_cgi.
>> Once I set up my httpd.conf and startup.pl files it no longer works. 
>> I get the following:
>>
>> Can't connect to MySQL server on 'localhost' (49)
>>
>> I can't find what (49) means anywhere...
>>
> Tom
>
>
> -- 
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 265.8.5 - Release Date: 03.02.2005
>
>
>


Re: Need help getting DBI to work under mod_perl

Posted by Rici Lake <ri...@ricilake.net>.
On 6-Feb-05, at 12:46 PM, Jay Scherrer wrote:
>> Boysenberry Payne wrote:
>>> I'm able to run DBI->connect() fine when I run my .pl and .pm
>>> scripts as mod_cgi.
>>> Once I set up my httpd.conf and startup.pl files it no longer
>>> works. I get the following:
>>>
>>> Can't connect to MySQL server on 'localhost' (49)
>>>
>>> I can't find what (49) means anywhere...

It's a system error number. On FreeBSD, at least, it means this:

      49 EADDRNOTAVAIL Cannot assign requested address.  Normally 
results from
              an attempt to create a socket with an address not on this
              machine.

but YMMV


Re: Need help getting DBI to work under mod_perl

Posted by Boysenberry Payne <bo...@humaniteque.com>.
So I decided much to my chagrin to reinstall all of my DAMP system.
I was able to get apache installed, without being able to start it, as 
a DSO
using the layout=GNU and -enable-shared=max configure options.
I probably need to be more selective but, I'll rebuild it once I get it 
working.
The make install on apache_1.3.33 says it's all ok, but when I try and
apachectl start it, I get:

dyld: /usr/local/sbin/httpd Undefined symbols:
_include_module
/usr/sbin/apachectl: line 186:  6269 Trace/BPT trap          $HTTPD

It's the same with compiling mod_perl 1.26.  I try to perl MakeFile.PL 
EVERYTHING=1 DO_HTTP=1
It says ok, but on make I get the following:

ld: warning multiple definitions of symbol _regcomp
regex/libregex.a(regcomp.o) definition of _regcomp in section 
(__TEXT,__text)
/usr/lib/libdl.dylib(regcomp.So) definition of _regcomp
ld: warning multiple definitions of symbol _regexec
regex/libregex.a(regexec.o) definition of _regexec in section 
(__TEXT,__text)
/usr/lib/libdl.dylib(regexec.So) definition of _regexec
ld: warning multiple definitions of symbol _regfree
regex/libregex.a(regfree.o) definition of _regfree in section 
(__TEXT,__text)
/usr/lib/libdl.dylib(regfree.So) definition of _regfree
ld: Undefined symbols:
_actions_module
_include_module
_log_config_module
make[1]: *** [target_static] Error 1
make: *** [apache_httpd] Error 2

I've tried so many different things and feel like I'm lost in the dark.
Anyone know how I can set things strait?


On Feb 6, 2005, at 4:16 PM, Boysenberry Payne wrote:

> I think I figured out what's wrong, but I don't know how to correct it.
> After reading a web-blog that said to rename any fink created 
> conflicting
> directories namely /sw/lib/mysql or /sw/lib/perl5 I tried it.  Nothing 
> worked
> afterwords.  So, I'm guessing I have conflicting modules being used.
> Try as I might to reinstall mod_perl I can't get it right.  The perl 
> MakeFile.PL
> asks me to find the apache source directory, which on Mac OS X 10.3 is
> /usr/include/httpd/ I believe.  When I try it the sub directories it 
> looks for
> the apache handlers are all wrong.  I tried ln my 
> /Library/MySQL/lib/mysql/
> to the /sw/lib/mysql/ directory to no avail.  I needs the following:
>
> dyld: /usr/sbin/httpd can't open library: 
> /sw/lib/mysql/libmysqlclient.14.dylib  (No such file or directory, 
> errno = 2)
> [Sun Feb  6 16:08:18 2005] [notice] child pid 779 exit signal 
> Trace/BPT trap (5)
>
> Anyone know what my next step is?


Re: Need help getting DBI to work under mod_perl

Posted by Boysenberry Payne <bo...@humaniteque.com>.
I think I figured out what's wrong, but I don't know how to correct it.
After reading a web-blog that said to rename any fink created 
conflicting
directories namely /sw/lib/mysql or /sw/lib/perl5 I tried it.  Nothing 
worked
afterwords.  So, I'm guessing I have conflicting modules being used.
Try as I might to reinstall mod_perl I can't get it right.  The perl 
MakeFile.PL
asks me to find the apache source directory, which on Mac OS X 10.3 is
/usr/include/httpd/ I believe.  When I try it the sub directories it 
looks for
the apache handlers are all wrong.  I tried ln my 
/Library/MySQL/lib/mysql/
to the /sw/lib/mysql/ directory to no avail.  I needs the following:

dyld: /usr/sbin/httpd can't open library: 
/sw/lib/mysql/libmysqlclient.14.dylib  (No such file or directory, 
errno = 2)
[Sun Feb  6 16:08:18 2005] [notice] child pid 779 exit signal Trace/BPT 
trap (5)

Anyone know what my next step is?


On Feb 6, 2005, at 11:46 AM, Jay Scherrer wrote:

> It's trying to connect to port 49. By default MySQL listens to 3606.
> Somewhere it was changed.
> Jay Scherrer
> On Sunday 06 February 2005 06:24 am, Tom Schindl wrote:
>> Give it a try and add the hostname you are connecting to to the
>> DSN.
>>
>> Tom
>>
>> Boysenberry Payne wrote:
>>> I'm able to run DBI->connect() fine when I run my .pl and .pm
>>> scripts as mod_cgi.
>>> Once I set up my httpd.conf and startup.pl files it no longer
>>> works. I get the following:
>>>
>>> Can't connect to MySQL server on 'localhost' (49)
>>>
>>> I can't find what (49) means anywhere...
>>
>> Tom
>
>


Re: Need help getting DBI to work under mod_perl

Posted by Jay Scherrer <ja...@scherrer.com>.
It's trying to connect to port 49. By default MySQL listens to 3606. 
Somewhere it was changed. 
Jay Scherrer
On Sunday 06 February 2005 06:24 am, Tom Schindl wrote:
> Give it a try and add the hostname you are connecting to to the
> DSN.
>
> Tom
>
> Boysenberry Payne wrote:
> > I'm able to run DBI->connect() fine when I run my .pl and .pm
> > scripts as mod_cgi.
> > Once I set up my httpd.conf and startup.pl files it no longer
> > works. I get the following:
> >
> > Can't connect to MySQL server on 'localhost' (49)
> >
> > I can't find what (49) means anywhere...
>
> Tom

Re: Need help getting DBI to work under mod_perl

Posted by Tom Schindl <to...@gmx.at>.
Give it a try and add the hostname you are connecting to to the DSN.

Tom
Boysenberry Payne wrote:

> I'm able to run DBI->connect() fine when I run my .pl and .pm scripts 
> as mod_cgi.
> Once I set up my httpd.conf and startup.pl files it no longer works. I 
> get the following:
>
> Can't connect to MySQL server on 'localhost' (49)
>
> I can't find what (49) means anywhere...
>
Tom


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.5 - Release Date: 03.02.2005


Re: Need help getting DBI to work under mod_perl

Posted by jonathan vanasco <jv...@mastersofbranding.com>.
On Feb 6, 2005, at 1:09 AM, Boysenberry Payne wrote:
> I running Mac OS X darwin, and get everything as showing correctly in 
> the %ENV.
> my $dsn = "DBI:mysql:database=test";
> my $test_db = eval{ DBI->connect( $dsn, "...", "...", { RaiseError => 
> 1, PrintError => 1, AutoCommit => 1 } ) };

first off, i'd double check that you can connect to the db test with 
the values '...' for user and pass that you substituted '...' with  
above

forever, i've used the same simple chunk of code, which has worked fine 
under osx + mod_perl
it gives me a db object that holds all of the db handles i  need (so i 
can create sep. handles for a write master or read slaves), and i just 
access everything through there per project

it generally looks like this
===========================================================
package my::DB;
use DBI;
my  $DB 		= 'dbi:mysql:test';
my  $DBuser 	= 'test';
my  $DBpass 	= 'test';
sub new
{
	my  $proto = shift;
	my  $class = ref($proto) || $proto;
	my  $this  = bless ( {} , $class);
		$this->dbconnect;
	return $this;
}
sub dbconnect
{
   my  $this = $_[0];
   $this->{'DBH'} = DBI->connect( $DB, $DBuser, $DBpass );
   if (!defined $this->{'DBH'} )
   {
     print STDERR "Cannot connect to sql server !";
   }
   print STDERR "CONNECTING VIA $DB DB \n";
}
1;


Re: Need help getting DBI to work under mod_perl

Posted by Boysenberry Payne <bo...@humaniteque.com>.
I surrounded the DBI->connect with an eval{} or confess() and got the  
following:

Bad at /Users/WebRoot/perl/updater.pl line 19
	Apache::ROOT::perl::updater_2epl::handler('Apache=SCALAR(0x8c7c10)')  
called at  
/System/Library/Perl/5.8.1/darwin-thread-multi-2level/Apache/ 
Registry.pm line 143
	eval {...} called at  
/System/Library/Perl/5.8.1/darwin-thread-multi-2level/Apache/ 
Registry.pm line 143
	Apache::Registry::handler('Apache=SCALAR(0x8c7c10)') called at  
/dev/null line 0
	eval {...} called at /dev/null line 0

Maybe this will make more sense to someone here...

Thanks,
Boysenberry