LoginSignup
1
2

More than 5 years have passed since last update.

MacOSXでビルドしたPHP7でpgsql.soを組み込む方法

Last updated at Posted at 2015-07-01

PHP7をソースから自分でビルドしたところ、pgsql周りの拡張がうまくインストールできませんでした。

環境:OSX Yosemite, PHP7 alpha, PostgreSQL93

MySQL系はconfigureのオプションですんなりと入ったのですが、

./configure --with-mysqli=mysqlnd \
            --with-pdo-mysql=mysqlnd \

pgsqlは

./configure --with-pgsql=/usr/local/Cellar/postgresql93/9.3.5

のようにしてもダメでした。(PostgreSQLデーモン本体はhome brewで先に入れてます)

解決方法: phpizeを使う

phpのソースツリーの中にext/pgsqlというのがあるので、ここで phpizeしてビルドすればOKでした。

☁  cd php-src/ext/pgsql
☁  pgsql ⚡  phpize
Configuring for:
PHP Api Version:         20131218
Zend Module Api No:      20141001
Zend Extension Api No:   320140815
☁  pgsql [9876b2c] ⚡  phpize
Configuring for:
PHP Api Version:         20131218
Zend Module Api No:      20141001
Zend Extension Api No:   320140815
☁  pgsql [9876b2c] ⚡  ./configure
checking for grep that handles long lines and -e... /usr/local/bin/ggrep
checking for egrep... /usr/local/bin/ggrep -E
checking for a sed that does not truncate output... /usr/local/bin/gsed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-apple-darwin14.3.0
checking host system type... x86_64-apple-darwin14.3.0
checking target system type... x86_64-apple-darwin14.3.0
checking for PHP prefix... /opt/php-master
checking for PHP includes... -I/opt/php-master/include/php -I/opt/php-master/include/php/main -I/opt/php-master/include/php/TSRM -I/opt/php-master/include/php/Zend -I/opt/php-master/include/php/ext -I/opt/php-master/include/php/ext/date/lib
checking for PHP extension directory... /opt/php-master/lib/php/extensions/debug-non-zts-20141001
checking for PHP installed headers prefix... /opt/php-master/include/php
checking if debug is enabled... yes
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.14.2 (ok)
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking for PostgreSQL support... yes, shared
checking for pg_config... /usr/local/bin/pg_config
checking for PQescapeString in -lpq... yes

中略

checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged

☁  pgsql [9876b2c] ⚡  sudo make
Password:
/bin/sh /Users/DQNEO/src/github.com/php/php-src/ext/pgsql/libtool --mode=install cp ./pgsql.la /Users/DQNEO/src/github.com/php/php-src/ext/pgsql/modules
cp ./.libs/pgsql.so /Users/DQNEO/src/github.com/php/php-src/ext/pgsql/modules/pgsql.so
cp ./.libs/pgsql.lai /Users/DQNEO/src/github.com/php/php-src/ext/pgsql/modules/pgsql.la
----------------------------------------------------------------------
Libraries have been installed in:
   /Users/DQNEO/src/github.com/php/php-src/ext/pgsql/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.

ここからが問題なのですが、sudo make installしたらうまく行きませんでした。(原因は不明)
その代わりにビルド結果のpgsql.soファイルを直接extension direcotryにコピーして置いたらうまく行きました。

☁  pgsql [9876b2c] ⚡  sudo cp modules/pgsql.so /opt/php-master/lib/php/extensions/debug-non-zts-20141001/

この後php.iniに extension=pgsql.soを追記したら、

☁  pgsql [9876b2c] ⚡  php -i | grep -i pgs
pgsql
pgsql.allow_persistent => On => On
pgsql.auto_reset_persistent => Off => Off
pgsql.ignore_notice => Off => Off
pgsql.log_notice => Off => Off
pgsql.max_links => Unlimited => Unlimited
pgsql.max_persistent => Unlimited => Unlimited

これでPHP7でpgsqlが使えるようになりました。

1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2