Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


I can easily connect to a remote MySQL server using the DBI module in my Perl scripts. However, when I try to use the same connection settings/properties from within a CGI script AND call it via browser, the MySQL connection fails to establish.

There are no helpful errors/warnings being logged either in the apache error log, or the browser, in spite of using

use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

I'm getting the following error:

 DBI connect('$db_name:$remote_host_IP:$port','$username',...) failed: Can't connect to MySQL server on '$remote_host_IP' (13) at /var/www/cgi-bin/$script_name.cgi line 25

Of course the logs contain the actual values of the abovementioned variables

I'm using the following connection string

$dbh = DBI->connect($ds, $uname, $pwd,{RaiseError => 1 }) or die "$DBI::errstr Could not connect: $!<br>";

Strangely, the exact same CGI script works fine when executed from the terminal (from within same cgi-bin directory), even after sudo'ing to the apache/tomcat user

On the other hand, phpMyAdmin works great on the machine, connecting to a different MySQL server on localhost.

I'm using CentOS Release 5.8. However, before writing the scripts, I had to install mysql server and client from a third-party repository via yum, because CentOS would not update PHP and the related php-mysql library to 5.2 or higher, for which a mysql upgrade was necessary (which also could not be done under my setup).

Which environment variables/libraries can I further look into to debug this issue?

Thanks a lot

In reply to CGI script connecting via terminal but not via browser by nkrgupta

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (2)
    As of 2018-05-22 01:16 GMT
    Find Nodes?
      Voting Booth?