Page 1 of 1

PHP and PostgreSql on Webmin

Posted: Sun Mar 15, 2009 5:54 pm
by Solakov
Hi there!

I just installed Webmin on my dedicated server and I really had hard time making all configuration that were needed to migrate my site. Anyway, now everything is working except for one thing. I can’t connect to the database through PHP. Remote connection is working fine, but local doesn’t.
The connection string looks like this:

pg_connect('host=localhost user=user password=pass dbname=db')

I made the necessary changes in postgresql.conf
listen_addresses = '*'
port=5432

And I added this in pg_nba.conf:

local all all trust
local all user ident sameuser
local db user password

But still I cannot connect on localhost using php. The connection file is the same as it was on my previous host (shared one) so it’s supposed to be working.
I created the same database and user.

Any idea?

Thanks in advance!

P.S.
I know that this is mostly DB issue, and I already posted this same question on Postgre user group, but no answer :(

Re: PHP and PostgreSql on Webmin

Posted: Mon Mar 16, 2009 7:04 am
by VladSun
Try this one in you pg_hba.conf

Code: Select all

#TYPE       DATABASE            USER        CIDR-ADDRESS        METHOD
 
# IPv4 local connections:
host        your_db_name        your_user_name     127.0.0.1/32        md5

Re: PHP and PostgreSql on Webmin

Posted: Mon Mar 16, 2009 1:56 pm
by Solakov
VladSun wrote:Try this one in you pg_hba.conf

Code: Select all

#TYPE       DATABASE            USER        CIDR-ADDRESS        METHOD
 
# IPv4 local connections:
host        your_db_name        your_user_name     127.0.0.1/32        md5
Already tried that, but still I get the same message: Warning: pg_pconnect() [function.pg-pconnect]: Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?

Anyway I managed to connect to localhost, but after I made changes to pg_connect and I removed the host name
FROM

Code: Select all

pg_pconnect("host=localhost dbname=mydb user=myuser password=mypassword");
TO

Code: Select all

pg_pconnect("dbname=mydb user=myuser password=mypassword");
Now it works, but VERY SLOWER than before.
One of the scripts I'm running on the previous host took below 2 sec for 1000 entries and now it takes 1 sec for 100 entries.

working pg_hba.conf looks like this:

Code: Select all

# IPv4 local connections:
 local   all         all                               trust
 local   all         my_user                          ident sameuser
 local my_db my_user password
 host my_db my_user 0.0.0.0/0 password
# IPv6 local connections:
 host    all         all         127.0.0.1/32          ident sameuser
 host    all         all         ::1/128               ident sameuser

Re: PHP and PostgreSql on Webmin

Posted: Mon Mar 16, 2009 3:05 pm
by VladSun
Warning: pg_pconnect() [function.pg-pconnect]: Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?
Perhaps the PGSQL server is not running on localhost but on some other machine. That would explain (probably) the slower performance you get (e.g. network related problems).

What about using:

pg_connect('host=127.0.0.1 user=user password=pass dbname=db')

Re: PHP and PostgreSql on Webmin

Posted: Mon Mar 16, 2009 5:08 pm
by Solakov
VladSun wrote:
Warning: pg_pconnect() [function.pg-pconnect]: Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?
Perhaps the PGSQL server is not running on localhost but on some other machine. That would explain (probably) the slower performance you get (e.g. network related problems).

What about using:

pg_connect('host=127.0.0.1 user=user password=pass dbname=db')
No, its running in the same machine for sure, I installed it.
127.0.0.1 doesn't work as well.
I'll stick with pg_connect('huser=user password=pass dbname=db') it works fine.

Probably the speed issue is because of the settings in postgresql.conf. They are not configured for the new machine (xeon quad, 8GB ram) and they are using the default settings.

I'll try now to change and find the best configuration.

anyway... MERSI FOR THE HELP :)