Databases

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • php can't connect to postgresql server

    6 answers - 1135 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    php can't connect to postgresql server
    php error log message:
    PHP Warning: pg_connect() [<a
    href='function.pg-connect'>function.pg-connect</a>]: Unable to connect
    to PostgreSQL server: could not connect to server: Permission
    denied\n\tIs the server running on host "127.0.0.1" and
    accepting\n\tTCP/IP connections on port 5432?
    php connection string:
    $conn_string = "hostaddr=127.0.0.1 port=5432 dbname=dbname
    user=username password=password";
    Also tried host=localhost
    pg_hba:
    host dbname username 127.0.0.1/32 md5
    I can connect as that user with psql:
    $ psql -h localhost -U username dbname
    Password for user username:
    Welcome to psql 8.1.4, the PostgreSQL interactive terminal.
    This same setup works in another server running 8.0. Differences:
    old server | new server
    FC3 | FC5
    php 4.3.11 | php 5.1.4
    httpd 2.0 | httpd 2.2
    What else should I check? I am out of ideas.
    Regards, Clodoaldo Pinto
    (end of broadcast)
    TIP 2: Don't 'kill -9' the postmaster
  • No.1 | | 1039 bytes | |

    2006/7/3, A. Kretschmer <andreas.kretschmer (AT) schollglas (DOT) com>:
    am 03.07.2006, um 10:25:29 -0300 mailte Clodoaldo Pinto folgendes:
    $conn_string = "hostaddr=127.0.0.1 port=5432 dbname=dbname
    ^^^^^^^^^

    I can connect as that user with psql:

    $ psql -h localhost -U username dbname
    ^^^^^^^^^

    Try 'localhost' instead '127.0.0.1' in your $conn_string.

    As I already said I have tried localhost also.

    My guess: pg don't listen on tcp/ip, only on the local socket.
    (check listen_addresses in your postgresql.conf)

    listen_addresses = '127.0.0.1,xx.xx.xxx.xx'

    If I can connect with the -h localhost psql's option then I guess it
    is listening to tcp/ip, isn't it?

    Clodoaldo

    (end of broadcast)
    TIP 1: if posting/reading through Usenet, please send an appropriate
    subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
    message can get through to the mailing list cleanly
  • No.2 | | 479 bytes | |

    am 03.07.2006, um 10:25:29 -0300 mailte Clodoaldo Pinto folgendes:
    $conn_string = "hostaddr=127.0.0.1 port=5432 dbname=dbname
    ^^^^^^^^^

    I can connect as that user with psql:

    $ psql -h localhost -U username dbname
    ^^^^^^^^^

    Try 'localhost' instead '127.0.0.1' in your $conn_string.

    My guess: pg don't listen on tcp/ip, only on the local socket.
    (check listen_addresses in your postgresql.conf)

    HTH, Andreas
  • No.3 | | 1498 bytes | |

    2006/7/3, Robert Treat <xzilla (AT) users (DOT) sourceforge.net>:
    Monday 03 July 2006 09:25, Clodoaldo Pinto wrote:
    php can't connect to postgresql server

    php error log message:

    PHP Warning: pg_connect() [<a
    href='function.pg-connect'>function.pg-connect</a>]: Unable to connect
    to PostgreSQL server: could not connect to server: Permission
    denied\n\tIs the server running on host "127.0.0.1" and
    accepting\n\tTCP/IP connections on port 5432?

    php connection string:

    $conn_string = "hostaddr=127.0.0.1 port=5432 dbname=dbname
    user=username password=password";

    Also tried host=localhost
    --
    It needs to be host, not hostaddr.

    Changed to host=localhost as I had already done before with the same
    results. From the php manual:

    "The currently recognized parameter keywords are: host, hostaddr,"

    What else should I check? I am out of ideas.
    --
    Make sure that your postgresql.conf "listen_addresses" is properly set,

    What do you mean by properly set? What I had already post is not properly set?:

    listen_addresses = '127.0.0.1,xx.xx.xxx.xx'

    make sure you dont have a firewall setting that is blocking connections, the
    default firewall settings on FC boxes are notorious for blocking pg.

    the 5432 port in the firewall and still the same problem.

    Clodoaldo

    (end of broadcast)
    TIP 6: explain analyze is your friend
  • No.4 | | 1342 bytes | |

    Monday 03 July 2006 09:25, Clodoaldo Pinto wrote:
    php can't connect to postgresql server

    php error log message:

    PHP Warning: pg_connect() [<a
    href='function.pg-connect'>function.pg-connect</a>]: Unable to connect
    to PostgreSQL server: could not connect to server: Permission
    denied\n\tIs the server running on host "127.0.0.1" and
    accepting\n\tTCP/IP connections on port 5432?

    php connection string:

    $conn_string = "hostaddr=127.0.0.1 port=5432 dbname=dbname
    user=username password=password";

    Also tried host=localhost

    It needs to be host, not hostaddr.

    pg_hba:

    host dbname username 127.0.0.1/32 md5

    I can connect as that user with psql:

    $ psql -h localhost -U username dbname
    Password for user username:
    Welcome to psql 8.1.4, the PostgreSQL interactive terminal.

    This same setup works in another server running 8.0. Differences:

    old server | new server
    FC3 | FC5
    php 4.3.11 | php 5.1.4
    httpd 2.0 | httpd 2.2

    What else should I check? I am out of ideas.

    Make sure that your postgresql.conf "listen_addresses" is properly set, also
    make sure you dont have a firewall setting that is blocking connections, the
    default firewall settings on FC boxes are notorious for blocking pg.
  • No.5 | | 1347 bytes | |

    2006/7/3, Clodoaldo Pinto <clodoaldo.pinto (AT) gmail (DOT) com>:
    php can't connect to postgresql server

    php error log message:

    PHP Warning: pg_connect() [<a
    href='function.pg-connect'>function.pg-connect</a>]: Unable to connect
    to PostgreSQL server: could not connect to server: Permission
    denied\n\tIs the server running on host "127.0.0.1" and
    accepting\n\tTCP/IP connections on port 5432?

    php connection string:

    $conn_string = "hostaddr=127.0.0.1 port=5432 dbname=dbname
    user=username password=password";

    Also tried host=localhost

    pg_hba:

    host dbname username 127.0.0.1/32 md5

    I can connect as that user with psql:

    $ psql -h localhost -U username dbname
    Password for user username:
    Welcome to psql 8.1.4, the PostgreSQL interactive terminal.

    This same setup works in another server running 8.0. Differences:

    old server | new server
    FC3 | FC5
    php 4.3.11 | php 5.1.4
    httpd 2.0 | httpd 2.2

    What else should I check? I am out of ideas.

    The same script running from another server can connect to the new
    server using this pg_hba entry:
    host dbname usename xx.xx.xxx.xx/32 md5

    Clodoaldo

    (end of broadcast)
    TIP 2: Don't 'kill -9' the postmaster
  • No.6 | | 1954 bytes | |

    2006/7/3, Clodoaldo Pinto <clodoaldo.pinto (AT) gmail (DOT) com>:
    2006/7/3, Clodoaldo Pinto <clodoaldo.pinto (AT) gmail (DOT) com>:
    php can't connect to postgresql server

    php error log message:

    PHP Warning: pg_connect() [<a
    href='function.pg-connect'>function.pg-connect</a>]: Unable to connect
    to PostgreSQL server: could not connect to server: Permission
    denied\n\tIs the server running on host "127.0.0.1" and
    accepting\n\tTCP/IP connections on port 5432?

    php connection string:

    $conn_string = "hostaddr=127.0.0.1 port=5432 dbname=dbname
    user=username password=password";

    Also tried host=localhost

    pg_hba:

    host dbname username 127.0.0.1/32 md5

    I can connect as that user with psql:

    $ psql -h localhost -U username dbname
    Password for user username:
    Welcome to psql 8.1.4, the PostgreSQL interactive terminal.

    This same setup works in another server running 8.0. Differences:

    old server | new server
    FC3 | FC5
    php 4.3.11 | php 5.1.4
    httpd 2.0 | httpd 2.2

    What else should I check? I am out of ideas.

    Solved. It was a SELinux problem. From /var/log/messages:

    kernel: audit(1151945653.900:39): avc: denied { name_connect } for
    pid=17167 comm="httpd" dest=5432
    tclass=tcp_socket

    Again followed this:

    #id2961385

    I searched for this problem and I wonder how could nobody reported it
    before. Am I the only one connecting locally to pgsql from php with
    SELinux enabled in a FC5 box or what?

    A much simpler solution:

    # setsebool -P httpd_can_network_connect_db 1

    Regards, Clodoaldo Pinto

    (end of broadcast)
    TIP 1: if posting/reading through Usenet, please send an appropriate
    subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
    message can get through to the mailing list cleanly

Re: php can't connect to postgresql server


max 4000 letters.
Your nickname that display:
In order to stop the spam: 0 + 9 =
QUESTION ON "Databases"

EMSDN.COM