Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to postgreSQL and web development and lately I tried to connect my previously created database via PHP. But things didn't worked out, I get the password authentication failed for the user postgres. I've been looking everywhere but can't find anything to solve this issue.

The database is hosted on my iMac, port 5432 and php script on heliohost.org which will be used later on to query the database.

Here is my php script:

<?php 
$host        = "host=127.0.0.1";
$port        = "port=5432";
$dbname      = "dbname=osm";
$credentials = "user=postgres password=newPassword";

$db = pg_connect( "$host $port $dbname $credentials"  ); 

if(!$db){
  echo "Error : Unable to open database\n";
} else {
  echo "Opened database successfully\n";
} 
?>

My pg_hba.conf looks like this :

local all postgres md5

and my postgresql.conf has : listen_addresses = localhost

I am a bit confused with this, if anyone have suggestion to get this up and running.

Thanks everyone!

share|improve this question
    
you're trying to run the script on your hosting provider and you're expecting to connect to your database running on your local computer? At the very least you have the wrong host name in the config (if that is indeed what you're trying to do) –  Cfreak Sep 2 '14 at 15:10

1 Answer 1

If you specify 127.0.0.1 as your host, it will attempt to hit your web server at heilohost.org, not your iMac. If you really want to do this (and there are a TON of reasons why it's a terrible idea), you'll have to set listen_address=0.0.0.0, forward the port on your router to your iMac, and use your public IP address in the connection string.

share|improve this answer
    
Thanks for your answer, I tried all said above but I got this error: Unable to connect to PostgreSQL server: could not connect to server: Connection refused Is the server running on host "my_computer_ip" and accepting TCP/IP connections on port 5432? –  TheProApps Sep 3 '14 at 12:39
    
Did you set your home router to forward connections on that port to your mac? How did you test it? Does your web hosting service allow outbound connections on random ports? –  PaulProgrammer Sep 3 '14 at 14:26
    
Thank you for your answers, I have opened my port 5432 which are now supposed to be open but tested it and can't access to my computer nor my database. So now I've decided to move to another server and I'm facing another issue, how can I run osm2pgsql when I have to connect to the database via SSH ? I am using A2hosting and they keep saying Osm2pgsql requires a SSH connection, which seems false as I connected the past weeks without ssh. Any idea ? I am so sorry to bother you, but I would like to get things working, sadly it's not right now. –  TheProApps Sep 11 '14 at 21:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.