php - Does setting a password on the postgres user mean that a password is required even when setting pg_hba.conf to trust? -
i have done of php/postgresql development under windows 7, migrating linux. have installed php , postgresql on debian wheezy, , having difficulty connecting postgresql database postgres user. found post on stackoverflow said following:
template1=# alter user postgres password 'password';
initially, password, used empty string, didn't work. next used text string, allowed me connect via pg_connect().
after doing more research, found altering pg_hba.conf file , making postgres user trusted wanted do... on making change, still getting errors when password isn't supplied via pg_connect() postgres user, question is:
does altering postgres user password cause pg_connect() require password when authentication method set trust? when connect via command line using:
psql -u postgres
i have no problems... problems begin when connecting via php using pg_connect().
pg_hba.conf file:
local postgres trust local trust host 127.0.0.1/32 md5 host ::1/128 md5
php connection line:
pg_connect('host=localhost dbname=dev user=postgres');
change pg_hba.conf
to:
local postgres trust local trust host 127.0.0.1/32 trust host ::1/128 trust
this allow connect without password.
remember restart (or reload) postgresql after edit pg_hba.conf
.
in alternative, can try change php code this:
pg_connect('dbname=dev user=postgres');
this should work without change pg_hba.conf
.
explanation:
you can connect postgres via unix socket (suggested, faster) or via tcp/ip. first , second line in pg_hba.conf
relative socket, third ipv4 , fourth ipv6. if specify localhost in code, you're connecting via tcp/ip (ipv4), , that's why didn't work , asked password.
if connect console psql -u postgres
, you're using unix socket, , that's why worked without password.
don't worry, changed configuration local connection granted access no password.
Comments
Post a Comment