DBIx::Simple, authentication fails

Discussion in 'Perl Misc' started by Justin Catterall, Jun 27, 2007.

  1. I have the following code to connect to a database:

    #!/usr/bin/perl

    use warnings ;
    use strict ;
    use DBIx::Simple ;
    use SQL::Abstract ;
    use CGI qw/:standard/ ;
    use CGI::Carp qw/fatalsToBrowser/ ;

    my $dataSource ;

    db_connect() ;

    print "Connected\n";

    sub db_connect {
    my $user = "name" ;
    my $password = "password" ;
    my $dataSource = DBIx::Simple->connect(
    'dbi:pg:database=prospects', $user, $password,
    { RaiseError => 1 , AutoCommit => 0 }
    ) or die DBI::Simple->error ;
    }

    If I run this from the command line "Connected" gets printed. If I run
    it from a browser I get:

    DBI connect('database=prospects','justin',...) failed: FATAL: Ident
    authentication failed for user "justin" at
    /var/www/inhouse/prospects/demo.cgi line 22

    Does anyone know why this should be?

    Thank you for your comments and suggestions.
    --
    Justin C, by the sea.
    Justin Catterall, Jun 27, 2007
    #1
    1. Advertising

  2. Justin Catterall

    Paul Lalli Guest

    On Jun 27, 9:40 am, Justin Catterall <> wrote:
    > I have the following code to connect to a database:


    <snip>

    > If I run this from the command line "Connected" gets printed. If I run
    > it from a browser I get:
    >
    > DBI connect('database=prospects','justin',...) failed: FATAL: Ident
    > authentication failed for user "justin" at
    > /var/www/inhouse/prospects/demo.cgi line 22
    >
    > Does anyone know why this should be?


    The user you're logged in as on the command line has access to the
    database. The user your webserver is running as does not.

    Fix the access permissions to your database.

    See also:
    $ perldoc -q 500
    Found in /software/perl-5.8.5-0/pkg/lib/5.8.5/pod/perlfaq9.pod
    My CGI script runs from the command line but not the
    browser. (500 Server Error)


    Paul Lalli
    Paul Lalli, Jun 27, 2007
    #2
    1. Advertising

  3. Justin Catterall

    Justin C Guest

    On 2007-06-27, Paul Lalli <> wrote:
    > On Jun 27, 9:40 am, Justin Catterall <> wrote:
    >> I have the following code to connect to a database:

    >
    ><snip>
    >
    >> If I run this from the command line "Connected" gets printed. If I run
    >> it from a browser I get:
    >>
    >> DBI connect('database=prospects','justin',...) failed: FATAL: Ident
    >> authentication failed for user "justin" at
    >> /var/www/inhouse/prospects/demo.cgi line 22
    >>
    >> Does anyone know why this should be?

    >
    > The user you're logged in as on the command line has access to the
    > database. The user your webserver is running as does not.
    >
    > Fix the access permissions to your database.
    >
    > See also:
    > $ perldoc -q 500
    > Found in /software/perl-5.8.5-0/pkg/lib/5.8.5/pod/perlfaq9.pod
    > My CGI script runs from the command line but not the
    > browser. (500 Server Error)


    Thank you Paul, adding www-data to the list of database users fixed
    this.

    Justin.

    --
    Justin Catterall www.masonsmusic.co.uk
    Director T: +44 (0)1424 427562
    Masons Music Ltd F: +44 (0)1424 434362
    For full company details see our web site
    Justin C, Jun 27, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Tobey
    Replies:
    0
    Views:
    518
    Al Tobey
    Oct 24, 2003
  2. I & L Fogg
    Replies:
    1
    Views:
    193
    Ben Morrow
    Jun 21, 2004
  3. shankar
    Replies:
    1
    Views:
    107
    J. Gleixner
    Mar 14, 2006
  4. Justin C
    Replies:
    5
    Views:
    199
    Justin C
    Jun 29, 2007
  5. Justin C
    Replies:
    3
    Views:
    147
    Paul Lalli
    Jul 7, 2007
Loading...

Share This Page