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 [EMAIL PROTECTED]
> 
> -- 
> Daryl Lee
> Open the present--it's a gift.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

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

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to