4

Is there anyway to connect to the Heroku postgres (Free) db instance from a locally running PHP application. I am able to get pgAdminIII successfully connected, but no luck through application connection string connecting to the same Db?

Connection

$dbconn = pg_connect("host=xxxxxx.compute-1.amazonaws.com port=5432 dbname=xxxxxxx user=xxxxxx password=xxxxxx sslmode=require options='--client_encoding=UTF8'");

Error Thrown from PHP Code:

 Warning: pg_connect(): Unable to connect to PostgreSQL server: sslmode value "require" invalid when SSL support is not compiled in in 

I found the following on Heroku's site but I am hoping someone can clarify whether I'm dealing with a postgres php issue (running PHP on Apache, PHP 5.3 on Mac OS X Lion 10.7.4) or if this is just an environment restriction as indicated in Heroku's following statement:

How do I connect to Heroku Postgres? Databases on Heroku Postgres accept standard PostgreSQL connections. Connections can be made from PostgreSQL client applications (such as psql, or PGAdmin), Application Frameworks (such as Ruby-on-Rails or Django), or any other libpq compatible client, from anywhere over SSL.

Shared databases however, can only be connected to from applications running on Heroku.

Can someone also explain why pgAdminIII is able to connect but my application cannont?

Thank you.

Further Findings: PHPINFO->

  • OpenSSL support enabled
  • OpenSSL Library Version OpenSSL 0.9.8r 8 Feb 2011
  • OpenSSL Header Version OpenSSL 0.9.8r 8 Feb 2011

  • PostgreSQL Support enabled

  • PostgreSQL(libpq) Version 8.2.23
  • SSL support disabled
2
  • You need to show more detail: the code, the connection string, the exact text of any error messages, etc. Sep 13, 2012 at 8:39
  • I am having the exact problem. Did you manage to solve it?
    – Chin
    May 3, 2013 at 5:21

1 Answer 1

1

So I spoke with a representative at Heroku. They confirmed for me that it does not require any specific tier of account to connect to a Heroku Postgres database, the only stipulation is that the connection uses ssl when connecting remotely. So my issue is the result of pgsql not having ssl support in my build of php.

3
  • How did you solved it? I'm facing a similar problem with my Wordpress installation in localhost; it doesn't connect to the Heroku DB... but it does correctly from Heroku. I'm using XAMPP and the pgsql PHP module is enabled. Version 8.0.3 and SSL support disabled :S.
    – Eneko
    Nov 3, 2012 at 17:25
  • The issue I ran into was the availability of ssl support for postgres which I dont' have available in my current PHP 5.x build. All connections to postgres in a shared db environment have to be over SSL. The requirement is not necessary (or is installed) when communicating within the Heroku platform. You should be able to connect to your Db via PgAdmin but I was never successful in a local host connection.
    – Ryan Fisch
    Nov 9, 2012 at 1:55
  • hi thank you @tafaju - how do you get the database URL? Because heroku may change this at any time?
    – BenKoshy
    Nov 8, 2016 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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