Page 1 of 2

cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 5:55 am
by jb489
Hi guys,

I have a problem which I just cant seem to solve. I am trying to connect to a postgreSQL database using php over ssl:

Now the postgreSQL database is not on the same machine. I know that the database has ssl built in because i am using pgAdminIII and connecting with ssl option as required. When I set this to disable, it doesnt connect at all. So therefore must have ssl built in.

Now for the code.

I am using the pg_connect as follows:

pg_connect($ConnectionString);
where $ConnectionString = "host=data.gf.com user=radedd password=pa55w0rd dbname=data sslmode=require port=5432"

and I am getting this error:
pg_connect(): Unable to connect to PostgreSQL server: sslmode value "require" invalid when SSL support is not compiled in

Can someone please help me on this as I am losing my mind trying to figure it out. I have tried googling in vain, every site says, configure your postgreSQL server, restart it(which I couldnt even if i wanted to as its a live system, and i clearly dont need to as pgadmin3 is connecting fine with ssl)

Please help guys...
Thanks to all..

Re: cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 6:22 am
by kaisellgren
I think PHP/PGSQL extension is not compiled with SSL support. Are you running on Linux?

Re: cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 6:26 am
by jb489
i am running on mac os x.

what do you mean by that?

i am quite new so please be patient :)

Re: cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 7:04 am
by kaisellgren
It's not about PostgreSQL database, it's because PHP is unable to use SSL. I think either PHP is not bundled/compiled with SSL or you don't have OpenSSL installed.

Re: cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 7:40 am
by jb489
can you point me in the right direction for installing openssl as i have looked high and low and cant find much for mac osx. Everything talks about uncommenting openssl.dll and this refers to a windows installation :(

Re: cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 8:03 am
by jb489
i did a phpinfo() and got this back under openssl. Does this mean i have openssl conpiled for php ?


openssl

OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.7l 28 Sep 2006

Re: cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 8:20 am
by kaisellgren
jb489 wrote:i did a phpinfo() and got this back under openssl. Does this mean i have openssl conpiled for php ?
At least you have the extension for OpenSSL loaded. Now, install OpenSSL if you have not already. If that's not enough, then you have to install/compile PHP with SSL support, but I don't know much about Mac's so I can't help there.

Re: cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 8:25 am
by jb489
install openssl, when you say that, is that some package or install it on the apache server ?

Re: cant connect to postgres server with ssl in php

Posted: Sun Aug 09, 2009 4:28 pm
by redmonkey
To get SSl support in for PostgreSQL in PHP you need to build/compile the PostgreSQL extension against a version of libpq that has in turn been compiled with SSL support.

Re: cant connect to postgres server with ssl in php

Posted: Mon Aug 10, 2009 3:33 am
by jb489
ok so i know i have php with ssl enabled from the phpinfo() stuff.

i know the postgreSQL server works with ssl cause pgadmin3 only connects to the database using ssl = required

now what do i do? I install openssl ?
i download it from here ?
http://www.openssl.org/

and where do i install it on the web server, client or postgres server ?
Is this a good installation procedure ?
http://openssl.darwinports.com/

thank you all for the information, i really appreciate it.

Re: cant connect to postgres server with ssl in php

Posted: Mon Aug 10, 2009 4:42 am
by redmonkey
Have a look at the output from phpinfo() under the 'pgsql' section, there is a section within that table output for 'SSL Support' it will be either enabled or disabled. If it's disabled (and your current PostgreSQL extension is a loadable module) you will have to get hold of (either compile or download) a PostgreSQL PHP extenstion with SSL support to replace your current one. If the PostgreSQL extenstion is compiled in to the main PHP binary, then you will have to get hold of a complete PHP binary replacement.

Re: cant connect to postgres server with ssl in php

Posted: Mon Aug 10, 2009 4:45 am
by jb489
i got this back,

this means that the php installation has ssl enabled and the the module loaded no?

openssl

OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.7l 28 Sep 2006

Re: cant connect to postgres server with ssl in php

Posted: Mon Aug 10, 2009 4:48 am
by jb489
now shall i install this, or has this been installed previously when I installed php with ssl support?

in terminal:
cd /opt/local/bin/portslocation/dports/openssl
sudo port install openssl
Password:

you should then see this:
---> Fetching openssl
---> Verifying checksum for openssl
---> Extracting openssl
---> Configuring openssl
---> Building openssl with target all

---> Staging openssl into destroot

---> Installing openssl

you can then use these commands
% man openssl
% apropos openssl
% which openssl
% locate openssl

Re: cant connect to postgres server with ssl in php

Posted: Mon Aug 10, 2009 4:50 am
by redmonkey
You need to look at the pgsql section. Just because you have the Openssl extension that doesn't mean that all other extensions will automatically have SSL support enabled, unfortunately it's not quite as simple as that.

Re: cant connect to postgres server with ssl in php

Posted: Mon Aug 10, 2009 4:52 am
by redmonkey
I'm not sure what flavour of OS X you have but previous OS X has shipped with a version Openssl installed, you probably don't need to install it again.