0

I developped a web app under CGI.pm.I'd like to switch to mod_perl2. My webapp worked under CGI but when i tried to change the mod, it's not working anymore while I didn't change anything in the webapp ,except the apache conf files to run under mod_perl.

I have installed mod-perl2 and configure my VirualHost like this :

Alias /project1/  /var/www/v6/cgi-bin/

PerlModule Apache::DBI
PerlModule ModPerl::RegistryPrefork

  <Directory /var/www/v6/cgi-bin/ >

        PerlOptions -SetupEnv
    SetHandler perl-script
    PerlResponseHandler ModPerl::RegistryPrefork
    PerlOptions +ParseHeaders
    Options +ExecCGI
    Order allow,deny
    Allow from all

  </Directory>

My script looks like . he uses some modules in /v6/cgi-bin/lib/

#!/usr/bin/perl 

    use lib qw(lib);
    use strict;
    use DBI;
    use CGI;
    use Template;
    use CGI::Carp qw(fatalsToBrowser);
    use Data::Dumper;

    use Connexion;
    use Search;

    my $cgi     = new CGI;

    our $fastdb = Connexion::database('1','1');
    my $get_description__id_sth  = Search->get_description_id_sth();

Apache2 write the error in the log :

[Thu Feb 3 17:35:13 2011] -e: DBI connect(':','',...) failed: Access denied for user 'www-data'@'localhost' (using password: NO) at lib/Connexion.pm line 134

In the browser i have :

Can't call method "prepare" on an undefined value at lib/Search.pm line 51.

So i understand that the script can't connect to the database.But why? It was working on mod_cgi. If someone has an idea :'( Thanks.

MICADO
  • 1
  • no *use warnings;*, here or in *Connexion* which would have caught the duplicated *$var* problem – MkV Feb 04 '11 at 07:51
  • also, as mentioned in one of the answers, turning off SetupEnv in PerlOptions removes some of the compatibility between mod_cgi and mod_perl – MkV Feb 04 '11 at 07:57

2 Answers2

1

What is Connexion and what is it doing in the DBI connect call?

You very likely need to not be disabling SetupEnv.

ysth
  • 96,171
  • 6
  • 121
  • 214
-1

Connexion is a module i made for connecting my database.It's in /cgi-bin/lib whereas my previous script call him from /cgi-bin/ directory.

package Connexion;

use strict;
use DBI;
sub database{

    my ($var,$var) = @_;
    my ($host1 ,$user1,$dbname1 ,$pass1)= '';

    if (($var== 1) and ($var ==1)){

        $host1              = 'localhost';
        $user1              = 'root';
        $dbname1            = 'BASE';
        $pass1              = '**';
     }

return my $fastdb = DBI -> connect ('DBI:mysql:' . $dbname1 . ':' . $host1, $user1, $pass1);
}
1;
ZheFrench
  • 1,164
  • 3
  • 22
  • 46
  • Missing a few lines (about 120) there. Also why not just return with DBI->connect instead of setting a variable? also, are you sure that *my ($host1, $user1, $dbname1, $pass1) = ''* is doing what you want? Lastly, you should add *RaiseError => 1* to the connect options to get informed of errors earlier. – MkV Feb 04 '11 at 07:38
  • Also isn't the connect string for DBD::mysql something like: *"DBI::mysql:database=$dbname1;host=$host1"*, not *"DBI:mysql:$dbname1:$host1"*? Presumably the duplicated *$var* in the my line and the if line are typos (why didn't you just copy and pate) – MkV Feb 04 '11 at 07:46
  • You didn't really show enough code here to be sure, but I think the problem has to do with whatever you're using for the password at Connextion.pm line 134. That's what this error is telling you: `Access denied for user 'www-data'@'localhost' (using password: NO) at lib/Connexion.pm line 134` – Perrin Harkins Sep 06 '14 at 16:12