ModPerl :: RegistryPrefork应该让我的旧cgi工作但是

时间:2011-02-03 17:46:05

标签: perl web-applications cgi mod-perl2

我在CGI.pm下开发了一个Web应用程序。我想切换到mod_perl2。 我的webapp在CGI下运行,但是当我尝试更改mod时,它不再工作了,而我没有更改webapp中的任何内容,除了在mod_perl下运行的apache conf文件。

我已经安装了mod-perl2并配置我的VirualHost:

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>

我的脚本看起来像。他在/ 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在日志中写入错误:

  

[Thu 2月3日17:35:13] -e:DBI   connect(':','',...)失败:访问   拒绝用户'www-data'@'localhost'   (使用密码:否)at   lib / Connexion.pm第134行

在浏览器中我有:

  

无法调用方法“准备”   lib / Search.pm行的未定义值   51。

所以我理解脚本无法连接到数据库。但为什么? 它正在研究mod_cgi。 如果有人有想法:'( 感谢。

2 个答案:

答案 0 :(得分:1)

什么是Connexion以及它在DBI连接呼叫中做了什么?

您很可能不需要禁用SetupEnv。

答案 1 :(得分:-1)

Connexion是我用来连接数据库的模块。它在/ cgi-bin / lib中,而我之前的脚本从/ cgi-bin /目录中调用它。

包装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;