5

I'm trying to connect to Heroku Postgres which only support SSL connections. SSL connection works fine from other tools (Postico) and programming environments (Node.js), but when connecting from PHP I always get this error: sslmode value "require" invalid when SSL support is not compiled

My local environment is OS X and all packages are installed with homebrew and have SSL support. Also pgsql has SSL support based on phpinfo() output: SSL support => enabled

Libpq and Postgres are compiled with SSL support: -lpgcommon -lpgport -lssl -lcrypto -lz -lreadline -lm

PHP version: 7.2.5 (also tried 5.6, 7.1 branches) Local Postgres and libpq version: 10.3

Tried every solution I could but can't get this connection working. Postgres support comes compiled out of box for PHP 7.2.5 when installing through homebrew. There is no more separate php-pgsql/php-pdo-pgsql package.

5
  • Possible duplicate of How to connect to Heroku postgres database from a local connection in php Commented May 10, 2018 at 11:50
  • Found that and a few other SO topics, but in my case the SSL support is compiled and looks like the problem is a bit different. From phpinfo(): "OpenSSL support => enabled" Commented May 11, 2018 at 7:54
  • Retracting flag then :) Commented May 11, 2018 at 9:13
  • So from local you are trying to connect a remote heroku PSQL? Also what is the output of php -i | grep -i SSL Commented May 18, 2018 at 4:41
  • Yes, that is the case. The output is quite large from that command, but here are some SSL related settings: SSL support => enabled OpenSSL support => enabled And PHP is built with this flag: '--with-openssl=/usr/local/opt/openssl' Commented May 18, 2018 at 7:54

2 Answers 2

5
+25

The error message is clear, it comes from this code in PostgreSQL's libpq:

#ifndef USE_SSL
        switch (conn->sslmode[0])
        {
            case 'a':           /* "allow" */
            case 'p':           /* "prefer" */

                /*
                 * warn user that an SSL connection will never be negotiated
                 * since SSL was not compiled in?
                 */
                break;

            case 'r':           /* "require" */
            case 'v':           /* "verify-ca" or "verify-full" */
                conn->status = CONNECTION_BAD;
                printfPQExpBuffer(&conn->errorMessage,
                                  libpq_gettext("sslmode value \"%s\" invalid when SSL support is not compiled in\n"),
                                  conn->sslmode);
                return false;
        }
#endif

That code is only compiled when PostgreSQL was not configured --with-openssl.

You can verify that with pg_config (if you didn't install PostgreSQL from source, you may have to install a "dev" or "devel" package for that):

pg_config --configure

The output will not contain --with-openssl.

It may well be that PHP is built with SSL support, but PostgreSQL isn't.

Since you say that PostgreSQL is compiled with SSL support, one explanation for the behavior is that there are several PostgreSQL installations on your machine, and PHP uses one that is build without SSL support. Try and find all files called libpq.* on your system!

Sign up to request clarification or add additional context in comments.

Comments

0

I ran into the same issue connecting to PostgreSQL on Heroku using MAMP with PHP7.2.1. Kept getting "sslmode value "require" invalid when SSL support is not compiled" even though openSSL and pgsql SSL support were showing as enabled in phpinfo(). Installing postgresql via homebrew fixed the issue for me.

brew install postgresql

Wanted to post in case this works for anyone else running into the same problem.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.