Sunday, February 11, 2018

Compile PHP PostgreSQL undefined symbol lo_lseek64() error

Upgrade PHP with PostgreSQL connect support


My php installed on OS X doesn't have PostgreSQL connect support, I need an upgrade.
$ brew install php56 --with-postgresql [--with-httpd]
doesn't work for my, so I try to compile manually from source.
Download the source from php.net. For PREFIX, you can set it to your preferred location, the /usr/local/Cellar location is used by Homebrew.

$ ./configure --prefix=/usr/local/Cellar/php/7.2.2 --with-pgsql=/usr/local/Cellar/postgres/10.2

This compile successfully, but I am not replacing the old php on the system, the apache always load the old php version. I need libphp.so (libphp5.so or libphp7.so) for apache to locate the new php.


$ ./configure --prefix=/usr/local/Cellar/php/7.2.2 --with-pgsql=/usr/local/Cellar/postgres/10.2 --with-apxs2=`which apxs`
(apxs command is from Apache)
This fail.
There are 3 groups of undefined symbols

1. undefined symbol _lo_lseek64()
- error from PostgreSQL, some issue with the configuration, I link it to libpq.a to solve.
2. undefined symbol _SSL_XXX
- link openssl-1.1, which is an older version on my system
3. Disable GSSAPI on Postgresql
- $ brew edit postgresql, delete --with-gssapi
- $ brew reinstall postgresql

You might not experience all the 3 issues.
How to link the missing library?
$ edit php-7.2.2/Makefile
For a quick hack, I just add in MH_BUNDLE_FLAGS =
either -L/usr/local/Cellar/postgresql/10.2 -lpq or /usr/local/Cellar/postgresql/10.2/lib/libpq.a
openssl
-L/usr/local/Cellar/openssl@1.1/lib -lcrypto -lssl
or
/usr/local/Cellar/openssl@1.1/lib/libcryptio.a /usr/local/Cellar/openssl@1.1/lib/libssl.a

My system is Mac OS X 10.9 Mavericks, Homebrew. I have tried compiling php-5.6 and php-7.2, both seems ok for me. I try php7.
$ ./configure --prefix=/usr/local/Cellar/php72/7.2.2_13 --with-mysqli=/usr/local/Cellar/mysql/5.6.25/bin/mysql_config --with-pdo-mysql=/usr/local/Cellar/mysql/5.6.25 --with-pgsql=/usr/local/Cellar/postgresql/10.2 --with-pdo-pgsql=/usr/local/Cellar/postgresql/10.2 --with-apxs2=`which apxs`
$ cp libs/libphp7.so /usr/local/libexec

$ edit /etc/apache2/httpd.conf
# LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/libexec/libphp5.so
LoadModule php7_module /usr/local/libexec/libphp7.so

$ sudo apachectl stop
$ sudo apachectl -M
...
rewrite_module (shared)
php5_module (shared)
php7_module (shared)
hfs_apple_module (shared)
Syntax OK
$ sudo apachectl start
$ curl http://localhost/php/phpinfo.php
()

PHP Version 7.2.2

PostgreSQL Support enabled