phppostgresqlmacosfpm

PHP pg_connect() does not return in PHP-FPM after MacOS Sonoma Upgrade


I have wasted a lot of time on this and I'm stumped. Anyone have some insight or work arounds? Thanks in advance for your attention...

My PHP/PostgreSQL/NGINX app has been running on MacOS using PHP-FPM installed via Homebrew for years. After upgrading MacOS to Sonoma 14.1 from 13.x, it no longer returns from pg_connect(). I've replicated this on 2 machines as well.

No PHP, NGINX, or PostgreSQL configurations have changed. Only the MacOS upgrade. PostgreSQL connects properly using psql and different --host parameters to access by the same interface.

I created a test script with just the pg_connect(), trying multiple permutations and discovered:

<?php
# The following line does not return and the request stops
$db = pg_connect("host=dbserver port=5432 dbname=appdb user=appuser");
echo "success!"
?>

Could MacOS now be preventing the connection until set to allow?

Versions: MacOS 14.1.1, PHP 8.2.13 also 8.3.0, PostgreSQL 15.5 server, also 16.1. libpq 16.1, nginx/1.25.3, Homebrew 4.1.21; Apple Mac M1


Solution

  • Finally I've found the solution here: https://github.com/laravel/valet/issues/1433#issuecomment-1741308660

    Add following lines to /opt/homebrew/etc/php/8.3/php-fpm.d/www.conf:

    env['PGGSSENCMODE'] = disable
    env['LC_ALL'] = C
    

    Then restart PHP. And it starts working!