Vilis
Vilis

Reputation: 1082

PHP & PostgreSQL – sslmode value "require" invalid when SSL support is not compiled

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.

Upvotes: 5

Views: 6248

Answers (2)

John F
John F

Reputation: 429

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.

Upvotes: 0

Laurenz Albe
Laurenz Albe

Reputation: 246848

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!

Upvotes: 5

Related Questions