php pgadmin remote db connect failure

2.2k views Asked by At

I want to connect to remote database from php to postgres but it could not connect and says

 Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server:    
could not connect to server: No route to host (0x00002751/10065) Is the server running on host "xxxxxxxxx" and accepting TCP/IP connections on port 5432? in C:\xampp\htdocs\test.php on line 4
Wrong CONN_STRING

<html> 
    <body> 
        <?php 
        $db = pg_connect('host=xxx.xxx.xxx.xxx port=5432 dbname=postgres user=postgres password=') or die('Wrong CONN_STRING'); 
        if (!$db) {
                echo 'error';
            }else{
            echo 'success';
            }

        ?> 
    </body> 

The same database I can access from pgadmin client which is running over same machine where apache is running, I could not understand that pgadmin can access db but apache webserver's php could not access ? any idea ?

2

There are 2 answers

0
d-man On BEST ANSWER

It was problem of SELinux Following command fixed the problem

setsebool -P httpd_can_network_connect=1

0
TML On

"No route to host" tells you that there is some kind of networking problem - the fact that a different client is able to access it from the same host would indicate it's some kind of security restriction or a firewall that is preventing the connection, but it's hard to be more specific without detailed information about your environment.