You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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

Posted on Oct 25, 2016 10:01 AM

Reply
4 replies

Jul 30, 2017 4:08 PM in response to bigmagic

Hello Nicolas,


I know this post is old, so I hope you will get notification that I am inquiring to your post. I have the same issue as above. I believe you know what you're doing, and began following your steps. Unfortunately, I don't seem to have the same directories as you've outlined. For instance:


- I don't have an ext/pgsql directory

- I don't have an /opt/ directory


I was hoping maybe you had an update? I'm running 10.11.6 (El Capitan) and Server 5.2.


I created a similar post in the macOS Server community a week or two ago, no one has replied to it as of yet.


Thanks for any help,


RJ30

Nov 10, 2016 11:36 AM in response to davidav

Hi,


I have the same issue on my Mac mini server which is running El Capitan.


The explanation is simple and It is a Apple's bug !


The two php modules below:

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


are compiled for php available under macOS sierra (PHP 5.6.25 - API=20131226).


For older Mac OS X like EL Capitan, PHP 5.5.38 (API=20121212) is provided and when you run php, It complains about the API mismatch :


# php -v

PHP Warning: PHP Startup: pdo_pgsql: Unable to initialize module

Module compiled with module API=20131226

PHP compiled with module API=20121212


I hope a fix will be available.


@Apple: It should be better to provide these two modules with the operating system's php binaries.


Best Regards,

Nicolas

Nov 15, 2016 8:52 AM in response to bigmagic

Hi,


The workaround is to rebuild yourself these two modules.


You will find below how to proceed


1/ Boot into Recovery mode


Diable the System Integrity Protection into the Recovery mode :

$ csrutil disable


2/ Restart into normal mode and build php modules


Download :

- php 5.5.38 from http://www.php.net/

- postgresql93 from MacPorts


Build PHP Modules:


$ cd ext/pgsql

$ PHP_AUTOCONF=/opt/local/bin/autoconf PHP_AUTOHEADER=/opt/local/bin/autoheader PATH=$PATH:/opt/local/bin phpize

$ export PATH=$PATH:/opt/local/bin PGSQL_INCLUDE=/opt/local/include/postgresql93/ PG_CONFIG=/opt/local/lib/postgresql93/bin/pg_config

$ ./configure --prefix=/usr \

--includedir=/opt/local/include \

--mandir=/usr/share/man \

--infodir=/usr/share/info \

--sysconfdir=/private/etc \

--with-pgsql=/opt/local/lib/postgresql93

$ make

$ make install


$ cd ../pdo_pgsql

$ PHP_AUTOCONF=/opt/local/bin/autoconf PHP_AUTOHEADER=/opt/local/bin/autoheader PATH=$PATH:/opt/local/bin phpize

$ ./configure --prefix=/usr \

--includedir=/opt/local/include \

--mandir=/usr/share/man \

--infodir=/usr/share/info \

--sysconfdir=/private/etc \

--with-pdo-pgsql=/opt/local/lib/postgresql93

$ make

$ make install


And modify the /Library/Server/Web/Config/php/php.ini with new extensions :


extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/pgsql.so

extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/pdo_pgsql.so


3/ Restart into Recovery mode :


Enable the System Integrity Protection

$ csrutil enable


It is working for me.


Best Regards,

Nicolas

PHP Warning: PHP Startup: pgsql: Unable to initialize module

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.