Question

I'm developing a Web Application under PHP with a remote database, in which I have the following test script:

try {
    $dbh = new PDO('mysql:host=XXX.XXX.XXX.XXX;dbname=db_app;', $user, $password);
    $date = ($dbh->query('SELECT NOW()');
    print_r($date);   
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
exit();

and when I run it I get the following output:

Error!: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '10.16.50.87' (60)

I can still connect to the target database using MySQL workbench and through Command Line Interface.

From this question I get that the remote server configuration "could have been" the problem. However, we have a "brother" PHP application connecting to the same server without problems, the only difference beetwen the two is the username and password, and even when running tests on my application using the "brother" PHP application credentials, the same error is shown. So it seems that only my PHP seems to have the problem.

I'm running tests on PHP 5.5.3 and the target server is running MySQL 5.5 Both My Application and the Brother Application are running on the Staging Server A, and both should be connecting to MySQL in Staging Server B. The Brother application is also written in PHP and is able to connect, but mine isn't. I'm guessing it could be a MySQL-relative PHP configuration.

  • My application uses PDO, while the brother application uses mysqli.

  • The brother application runs on the same server as my application, and connects to the same target server.

Any help would be appreciated.

Was it helpful?

Solution

For me it was SELinux causing the issues:

[root@server ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted
[root@server ~]# setenforce 0
[root@server ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

Run below as root:

setsebool -P httpd_can_network_connect=1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top