You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Daryl Lee <dl...@altaregos.com> on 2003/01/20 05:25:00 UTC

DBI/mod_perl2 failure

The following is the full report of a problem I'm having.  Any pointers
will be appreciated.  I'm worried I may have the wrong "mod_perl2"--it's
not clear to me why the version number should be "1.99_08"; I expected
"2.x".

-------------8<---------- Start Bug Report ------------8<----------
1. Problem Description:

   DBI doesn't connect to MySQL when running under mod_perl2's perl-script.

   The following script works correctly when run from the command line, as
	#cgi-bin/dbi.pl,
	or as a standard CGI script, i.e.,
	http://localhost/cgi-bin/dbi.pl.  
	But when run as precompiled under mod_perl2, i.e, as 
	http://localhost/cgi/dbi.pl,
	the connection fails with DBI=>errstr() reporting
	"Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)".
	The last line of error_log is:
DBI connect('people','apache',...) failed: Can't connect to local MySQL
server through socket '/tmp/mysql.sock' (2) at
/usr/local/apache2/perl/dbi.pl line 5
	I also installed Apache::DBI and "use"'d it, with the same result.


Script:

#!/usr/bin/perl
use strict;
use DBI;
# connect to the MySQL server
my $dbh = DBI->connect('DBI:mysql:people', 'apache', 'LampIsCool');
print "Content-type: text/plain\n\n";
if ($dbh) {
	print "Connected\n";
	$dbh->disconnect();
} else {
	print "Connection failed\n";
	print DBI->errstr();
}

The configuration section from httpd.conf is:
Alias /cgi /usr/local/apache2/perl
<Location /cgi>
  SetHandler                    perl-script
  PerlResponseHandler   ModPerl::Registry
  PerlOptions                   +ParseHeaders
</Location>


2. Used Components and their Configuration:
Besides the following output from t/REPORT, I have just installed
DBI v1.32 from CPAN.  mod_perl2 (1.99_08) was just installed a few days ago.

*** using lib/Apache/BuildConfig.pm
*** Makefile.PL options:
  MP_AP_PREFIX    => /usr/local/apache2
  MP_GENERATE_XS  => 1
  MP_INST_APACHE2 => 1
  MP_LIBNAME      => mod_perl
  MP_USE_DSO      => 1
  MP_USE_STATIC   => 1


*** /usr/local/apache2/bin/httpd -V
Server version: Apache/2.0.43
Server built:   Dec 11 2002 06:52:03
Server's Module Magic Number: 20020903:0
Architecture:   32-bit
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D HTTPD_ROOT="/usr/local/apache2"
 -D SUEXEC_BIN="/usr/local/apache2/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"


*** /usr/bin/perl -V
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.18-11smp, archname=i386-linux-thread-multi
    uname='linux daffy.perf.redhat.com 2.4.18-11smp #1 smp thu aug 15 06:41:59 edt 2002 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -march=i386 -mcpu=i686',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/include/gdbm'
    ccversion='', gccversion='3.2 20020822 (Red Hat Linux Rawhide 3.2-5)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=/lib/libc-2.2.92.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.2.92'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
  Built under linux
  Compiled at Sep  1 2002 23:56:49
  %ENV:
    PERL_LWP_USE_HTTP_10="1"
  @INC:
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    .


3. This is the core dump trace: (if you get a core dump):

   No core dump.  Error reported by DBI->errstr().

This report was generated by t/REPORT on Mon Jan 20 03:40:47 2003 GMT.

-------------8<---------- End Bug Report --------------8<----------

Note: Complete the rest of the details and post this bug report to
dev <at> perl.apache.org. To subscribe to the list send an empty
email to dev-subscribe@perl.apache.org.

-- 
Daryl Lee
Open the present--it's a gift.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: DBI/mod_perl2 failure

Posted by Stas Bekman <st...@stason.org>.
Daryl Lee wrote:
> The following is the full report of a problem I'm having.  Any pointers
> will be appreciated.  I'm worried I may have the wrong "mod_perl2"--it's
> not clear to me why the version number should be "1.99_08"; I expected
> "2.x".
> 
> -------------8<---------- Start Bug Report ------------8<----------
> 1. Problem Description:
> 
>    DBI doesn't connect to MySQL when running under mod_perl2's perl-script.
> 
>    The following script works correctly when run from the command line, as
> 	#cgi-bin/dbi.pl,
> 	or as a standard CGI script, i.e.,
> 	http://localhost/cgi-bin/dbi.pl.  
> 	But when run as precompiled under mod_perl2, i.e, as 
> 	http://localhost/cgi/dbi.pl,
> 	the connection fails with DBI=>errstr() reporting
> 	"Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)".
> 	The last line of error_log is:
> DBI connect('people','apache',...) failed: Can't connect to local MySQL
> server through socket '/tmp/mysql.sock' (2) at
> /usr/local/apache2/perl/dbi.pl line 5
> 	I also installed Apache::DBI and "use"'d it, with the same result.

It's weird that the error is not very descriptive. What about perms of 
/tmp/mysql.sock? it's possible that mod_cgi and mod_perl aren't running under 
the same username? Try printing out $< and $> from your script under CGI and 
mod_perl.

In any case, your script works just fine for me, though I was connecting to:

   my $dbh = DBI->connect('DBI:mysql:test', '', '');

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: DBI/mod_perl2 failure

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 21 Jan 2003, Daryl Lee wrote:

> Problem solved.  The root cause was staring me in my face and I missed it.
> Under mod_perl, the connection attempt was through /tmp/mysql.sock, but
> (for reasons that totally escape me) all other communication with mysql is
> through /var/lib/mysql/mysql.sock.  A symlink at /tmp pointing to the
> correct location fixed me right up.  There may be a cleaner solution, like
> using the /var... location directly, but at least I'm up and running.

That's great ... Perhaps the MYSQL_UNIX_PORT environment variable
has been set to point to /var/lib/mysql/mysql.sock, and mod_perl
doesn't see this, and so defaults to /tmp/mysql.sock. You might
try sticking in a PerlSetEnv or PerlPassEnv directive so that
mod_perl can see this.
 
-- 
best regards,
randy


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: DBI/mod_perl2 failure

Posted by Daryl Lee <dl...@altaregos.com>.
Problem solved.  The root cause was staring me in my face and I missed it.
Under mod_perl, the connection attempt was through /tmp/mysql.sock, but
(for reasons that totally escape me) all other communication with mysql is
through /var/lib/mysql/mysql.sock.  A symlink at /tmp pointing to the
correct location fixed me right up.  There may be a cleaner solution, like
using the /var... location directly, but at least I'm up and running.

Thanks to Randy and Stas, who jumped in and stirred the pot for me.

On Sun, Jan 19, 2003 at 11:25:00PM -0500, Daryl Lee wrote:
> The following is the full report of a problem I'm having.  Any pointers
> will be appreciated.  I'm worried I may have the wrong "mod_perl2"--it's
> not clear to me why the version number should be "1.99_08"; I expected
> "2.x".
> 
> -------------8<---------- Start Bug Report ------------8<----------
> 1. Problem Description:
> 
>    DBI doesn't connect to MySQL when running under mod_perl2's perl-script.
> 
>    The following script works correctly when run from the command line, as
> 	#cgi-bin/dbi.pl,
> 	or as a standard CGI script, i.e.,
> 	http://localhost/cgi-bin/dbi.pl.  
> 	But when run as precompiled under mod_perl2, i.e, as 
> 	http://localhost/cgi/dbi.pl,
> 	the connection fails with DBI=>errstr() reporting
> 	"Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)".
> 	The last line of error_log is:
> DBI connect('people','apache',...) failed: Can't connect to local MySQL
> server through socket '/tmp/mysql.sock' (2) at
> /usr/local/apache2/perl/dbi.pl line 5
> 	I also installed Apache::DBI and "use"'d it, with the same result.
> 
> 
> Script:
> 
> #!/usr/bin/perl
> use strict;
> use DBI;
> # connect to the MySQL server
> my $dbh = DBI->connect('DBI:mysql:people', 'apache', 'LampIsCool');
> print "Content-type: text/plain\n\n";
> if ($dbh) {
> 	print "Connected\n";
> 	$dbh->disconnect();
> } else {
> 	print "Connection failed\n";
> 	print DBI->errstr();
> }
> 
> The configuration section from httpd.conf is:
> Alias /cgi /usr/local/apache2/perl
> <Location /cgi>
>   SetHandler                    perl-script
>   PerlResponseHandler   ModPerl::Registry
>   PerlOptions                   +ParseHeaders
> </Location>
> 
> 
> 2. Used Components and their Configuration:
> Besides the following output from t/REPORT, I have just installed
> DBI v1.32 from CPAN.  mod_perl2 (1.99_08) was just installed a few days ago.
> 
> *** using lib/Apache/BuildConfig.pm
> *** Makefile.PL options:
>   MP_AP_PREFIX    => /usr/local/apache2
>   MP_GENERATE_XS  => 1
>   MP_INST_APACHE2 => 1
>   MP_LIBNAME      => mod_perl
>   MP_USE_DSO      => 1
>   MP_USE_STATIC   => 1
> 
> 
> *** /usr/local/apache2/bin/httpd -V
> Server version: Apache/2.0.43
> Server built:   Dec 11 2002 06:52:03
> Server's Module Magic Number: 20020903:0
> Architecture:   32-bit
> Server compiled with....
>  -D APACHE_MPM_DIR="server/mpm/prefork"
>  -D APR_HAS_SENDFILE
>  -D APR_HAS_MMAP
>  -D APR_HAVE_IPV6
>  -D APR_USE_SYSVSEM_SERIALIZE
>  -D APR_USE_PTHREAD_SERIALIZE
>  -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
>  -D APR_HAS_OTHER_CHILD
>  -D AP_HAVE_RELIABLE_PIPED_LOGS
>  -D HTTPD_ROOT="/usr/local/apache2"
>  -D SUEXEC_BIN="/usr/local/apache2/bin/suexec"
>  -D DEFAULT_PIDLOG="logs/httpd.pid"
>  -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
>  -D DEFAULT_LOCKFILE="logs/accept.lock"
>  -D DEFAULT_ERRORLOG="logs/error_log"
>  -D AP_TYPES_CONFIG_FILE="conf/mime.types"
>  -D SERVER_CONFIG_FILE="conf/httpd.conf"
> 
> 
> *** /usr/bin/perl -V
> Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
>   Platform:
>     osname=linux, osvers=2.4.18-11smp, archname=i386-linux-thread-multi
>     uname='linux daffy.perf.redhat.com 2.4.18-11smp #1 smp thu aug 15 06:41:59 edt 2002 i686 i686 i386 gnulinux '
>     config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr'
>     hint=recommended, useposix=true, d_sigaction=define
>     usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
>     useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
>     use64bitint=undef use64bitall=undef uselongdouble=undef
>     usemymalloc=n, bincompat5005=undef
>   Compiler:
>     cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
>     optimize='-O2 -march=i386 -mcpu=i686',
>     cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/include/gdbm'
>     ccversion='', gccversion='3.2 20020822 (Red Hat Linux Rawhide 3.2-5)', gccosandvers=''
>     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
>     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
>     ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
>     alignbytes=4, prototype=define
>   Linker and Libraries:
>     ld='gcc', ldflags =' -L/usr/local/lib'
>     libpth=/usr/local/lib /lib /usr/lib
>     libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
>     perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
>     libc=/lib/libc-2.2.92.so, so=so, useshrplib=true, libperl=libperl.so
>     gnulibc_version='2.2.92'
>   Dynamic Linking:
>     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
>     cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
> 
> 
> Characteristics of this binary (from libperl): 
>   Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
>   Built under linux
>   Compiled at Sep  1 2002 23:56:49
>   %ENV:
>     PERL_LWP_USE_HTTP_10="1"
>   @INC:
>     /usr/lib/perl5/5.8.0/i386-linux-thread-multi
>     /usr/lib/perl5/5.8.0
>     /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
>     /usr/lib/perl5/site_perl/5.8.0
>     /usr/lib/perl5/site_perl
>     /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
>     /usr/lib/perl5/vendor_perl/5.8.0
>     /usr/lib/perl5/vendor_perl
>     .
> 
> 
> 3. This is the core dump trace: (if you get a core dump):
> 
>    No core dump.  Error reported by DBI->errstr().
> 
> This report was generated by t/REPORT on Mon Jan 20 03:40:47 2003 GMT.
> 
> -------------8<---------- End Bug Report --------------8<----------
> 
> Note: Complete the rest of the details and post this bug report to
> dev <at> perl.apache.org. To subscribe to the list send an empty
> email to dev-subscribe@perl.apache.org.
> 
> -- 
> Daryl Lee
> Open the present--it's a gift.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
> For additional commands, e-mail: dev-help@perl.apache.org
> 
> 

-- 
Daryl Lee
Open the present--it's a gift.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: DBI/mod_perl2 failure

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Sun, 19 Jan 2003, Daryl Lee wrote:

> The following is the full report of a problem I'm having.  Any pointers
> will be appreciated.  I'm worried I may have the wrong "mod_perl2"--it's
> not clear to me why the version number should be "1.99_08"; I expected
> "2.x".

That version number is correct - mod_perl 1.99_xx is the
development version for mod_perl 2.0.

> -------------8<---------- Start Bug Report ------------8<----------
> 1. Problem Description:
> 
>    DBI doesn't connect to MySQL when running under mod_perl2's perl-script.
> 
>    The following script works correctly when run from the command line, as
> 	#cgi-bin/dbi.pl,
> 	or as a standard CGI script, i.e.,
> 	http://localhost/cgi-bin/dbi.pl.  
> 	But when run as precompiled under mod_perl2, i.e, as 
> 	http://localhost/cgi/dbi.pl,
> 	the connection fails with DBI=>errstr() reporting
> 	"Can't connect to local MySQL server through socket
> '/tmp/mysql.sock' (2)".
> 	The last line of error_log is:
> DBI connect('people','apache',...) failed: Can't connect to local MySQL
> server through socket '/tmp/mysql.sock' (2) at
> /usr/local/apache2/perl/dbi.pl line 5
> 	I also installed Apache::DBI and "use"'d it, with the same result.
> 
> Script:
> 
> #!/usr/bin/perl
> use strict;
> use DBI;
> # connect to the MySQL server
> my $dbh = DBI->connect('DBI:mysql:people', 'apache', 'LampIsCool');
> print "Content-type: text/plain\n\n";
> if ($dbh) {
> 	print "Connected\n";
> 	$dbh->disconnect();
> } else {
> 	print "Connection failed\n";
> 	print DBI->errstr();
> }
> 
> The configuration section from httpd.conf is:
> Alias /cgi /usr/local/apache2/perl
> <Location /cgi>
>   SetHandler                    perl-script
>   PerlResponseHandler   ModPerl::Registry
>   PerlOptions                   +ParseHeaders
> </Location>
> 
> 2. Used Components and their Configuration: Besides the
> following output from t/REPORT, I have just installed DBI v1.32
> from CPAN.  mod_perl2 (1.99_08) was just installed a few days
> ago.
[ ... ] 
> Characteristics of this binary (from libperl): 
>   Compile-time options: MULTIPLICITY USE_ITHREADS
> USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
>   Built under linux
>   Compiled at Sep  1 2002 23:56:49
>   %ENV:
>     PERL_LWP_USE_HTTP_10="1"
>   @INC:
>     /usr/lib/perl5/5.8.0/i386-linux-thread-multi
>     /usr/lib/perl5/5.8.0
>     /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
>     /usr/lib/perl5/site_perl/5.8.0
>     /usr/lib/perl5/site_perl
>     /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
>     /usr/lib/perl5/vendor_perl/5.8.0
>     /usr/lib/perl5/vendor_perl
>     .

Are DBI and DBD::mysql under site_perl/? If so, might there also
be versions of these (or perhaps other) modules under
vendor_perl/ that mod_perl is picking up, and perhaps getting
confused with?

-- 
best regards,
randy kobes


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org