Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

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

Hi,

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

Title:
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!
  • 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (13)
    As of 2015-07-01 17:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (12 votes), past polls