PHP Warning: PHP Startup: pgsql: Unable to initialize module
Near the end of September 2016, the following errors started occurring for PHP scripts on my server:
PHP Warning: PHP Startup: pdo_pgsql: Unable to initialize module
Module compiled with module API=20131226
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: pgsql: Unable to initialize module
Module compiled with module API=20131226
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
But then I found that the pdo_pgsql and pgsql extensions were not being loaded in the /etc/php.ini configuration file:
# cat /etc/php.ini | grep extension | grep pgsql
;extension=php_pdo_pgsql.dll
;extension=php_pgsql.dll
After some digging, I noticed that an additional php.ini file was added by macOS Server (highlighted in red below):
# php -i | grep php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
Additional .ini files parsed => /Library/Server/Web/Config/php/php.ini
Sure enough, the offending configurations were inside the macOS Server php.ini file, /Library/Server/Web/Config/php/php.ini (offending lines are in red below):
# cat /Library/Server/Web/Config/php/php.ini
; Server app overrides for PHP. Settings here take precedence over settings in /etc/php.ini
;
; Administrators should add custom PHP settings to /etc/php.ini; edits there will be preserved.
;
; If administrators apply custom settings this php.ini file, note that the Server app promotion
; process may rename this file to php.ini-previous and install a new php.ini, which will require
; that customized settings be manually moved from php.ini-previous to php.ini.
;
extension=/Applications/Server.app/Contents/ServerRoot/usr/lib/php/extensions/no -debug-non-zts-20131226/pdo_pgsql.so
extension=/Applications/Server.app/Contents/ServerRoot/usr/lib/php/extensions/no -debug-non-zts-20131226/pgsql.so
;zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
session.entropy_length = 20
session.entropy_file = /dev/random
session.hash_function = sha512
date.timezone = "America/Los_Angeles"
So apparently Apple decided to try to load these extensions from within the macOS Server application package, but since the version of the PHP API used by these extensions doesn't match the PHP API installed on the system, the extensions refuse to load correctly, causing PHP to spew error messages during startup.
Adding semicolon characters to comment out each of the red lines above was all that was needed to fix the issue. I haven't (yet?) noticed any problematic behavior resulting from disabling these extensions in the macOS Server php.ini file. The next time Server is updated, my change may get overwritten with a new copy of the file. So I'll have to check it each time I update. :/
Mac Pro, OS X El Capitan (10.11.3), null