我试过你的dockerfile脚本,发现了一些错误。Docker构建输出确实显示了对PDO模块进行解包和编译的痕迹:
但在PDO配置过程中失败,并出现错误:
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for Informix driver for PDO... yes, shared
configure: error: INFORMIXDIR environment variable is not set. Please use --with
-pdo-informix=<DIR> or set the INFORMIXDIR environment variable.
Removing intermediate container a73c9bfa211d
---> d86e02cc6801
Step 20/24 : COPY scripts/envvars.sh /tmp
我更改了构建模块的脚本,以便在运行configure之前设置informisdir。
checking for PHP extension directory... /usr/lib/php/20170718
checking for PHP installed headers prefix... /usr/include/php/20170718
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate
PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for Informix driver for PDO... yes, shared
checking for PDO includes... configure: error: Cannot find php_pdo_driver.h.
Removing intermediate container deee5a938a6e
又一次在别的地方失败了。查看模块构建文件时,它期望模块位于以下目录中:
-- config.m4 --
AC_MSG_CHECKING([for PDO includes])
if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then
pdo_inc_path=$abs_srcdir/ext
elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then
pdo_inc_path=$abs_srcdir/ext
elif test -f $prefix/include/php/ext/pdo/php_pdo_driver.h; then
pdo_inc_path=$prefix/include/php/ext
else
AC_MSG_ERROR([Cannot find php_pdo_driver.h.])
fi
但在IBM Docker映像中,该文件位于:
root@faf18c3c0ef5:/usr/include# find ./ -name php_pdo_driver.h
./php/20170718/ext/pdo/php_pdo_driver.h
root@faf18c3c0ef5:/usr/include#
所以我在dockerfile中添加了一个“ln-s”来创建软链接。
以下是我修改的两个文件:
---install-informixpdo.sh ---
...
PDO_DIRECTORY=PDO_INFORMIX-1.3.3
PDO_FILENAME=$PDO_DIRECTORY.tgz
export INFORMIXDIR=/opt/ibm/informix
TMPDIR=/tmp
tar -xvf $TMPDIR/$PDO_FILENAME -C $TMPDIR/
cd $TMPDIR/$PDO_DIRECTORY
phpize && ./configure && make && make install
rm -r $TMPDIR/*
...
----------
和
--- dockerfile ---
....
ENV INFORMIXDIR /opt/ibm/informix
ENV PATH $INFORMIXDIR/bin:$PATH
COPY scripts/PDO_INFORMIX-1.3.3.tgz /tmp
COPY scripts/install-informixpdo.sh /tmp
RUN sudo ln -s /usr/include/php/20170718/ext /usr/include/php/ext
RUN sudo sh /tmp/install-informixpdo.sh
#Informix environment variables for Apache
COPY scripts/envvars.sh /tmp
...
-------------
通过这些更改,我可以在执行“docker build”命令时编译并安装模块。
....
....
----------------------------------------------------------------------
Libraries have been installed in:
/tmp/PDO_INFORMIX-1.3.3/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 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib/php/20170718/
Removing intermediate container 43bc22fb8234
---> 256d3fabdc70
Step 22/26 : COPY envvars.sh /tmp
....
与apache配置一起使用的php加载模块:
root@99d4150d07ed:/# php -c /etc/php/7.2/apache2/conf.d/pdo.ini -m | grep inform
ix
pdo_informix
root@99d4150d07ed:/#
一个简单的连接,似乎也可以毫无问题地工作:
root@99d4150d07ed:/# cat t.php
<?php
$db = new PDO("informix:host=99d4150d07ed; service=9088;database=sysmaster; serv
er=informix; protocol=onsoctcp; EnableScrollableCursors=1;", "informix", "in4mix
");
print "Connection Established!</br></br>";
$stmt = $db->query("select * from systables");
$res = $stmt->fetch( PDO::FETCH_BOTH );
$rows = $res[0];
echo "Table contents: $rows.</br>";
?>
root@99d4150d07ed:/# php -c /etc/php/7.2/apache2/conf.d/pdo.ini t.php
Connection Established!</br></br>Table contents: systables.</br>root@99d4150d07e
d:/#
您可以在“install informixpdo.sh”文件中添加软链接创建和导出informixpdir。
编辑:
root@886a4870f1d0:/var/www/html# cat t.php
<?php
$db = new PDO("informix:host=".getenv('HOSTNAME')."; service=9088;database=sysmaster; server=informix; protocol=onsoctcp; EnableScrollableCursors=1;", "informix", "in4mix");
print "Connection Established!</br></br>";
$stmt = $db->query("select * from systables");
$res = $stmt->fetch( PDO::FETCH_BOTH );
$rows = $res[0];
echo "Table contents: $rows.</br>";
?>
root@886a4870f1d0:/var/www/html# php t.php
Connection Established!</br></br>Table contents: systables.</br>root@886a4870f1d0:/var/www/html#
root@886a4870f1d0:/var/www/html# curl http://localhost/t.php
Connection Established!</br></br>Table contents: systables.</br>root@886a4870f1d0:/var/www/html#
root@886a4870f1d0:/var/www/html#