我正在尝试使用apache2,php7.2和pdo_informix在docker中创建镜像,但是我没有成功,只是看不到扩展已启用,而且我不知道自己是否在执行错误的步骤。
我将分享到目前为止在以下存储库中拥有的内容:
here
Dockerfile:
FROM ibmcom/informix-developer-database
USER root
RUN sudo rm /var/lib/apt/lists/lock
RUN sudo apt-get update && sudo apt-get -y upgrade
RUN sudo apt-get install -y tzdata
RUN sudo apt-get install git nodejs npm composer nano tree vim curl ftp -y
ENV TZ=America/Bogota
ENV LICENSE=accept
RUN sudo apt-get -y install apache2
RUN sudo apt-get install -y \
php \
php-bz2 \
php-cgi \
php-cli \
php-common \
php-curl \
php-dev \
php-enchant \
php-fpm \
php-gd \
php-gmp \
php-imap \
php-interbase \
php-intl \
php-json \
php-ldap \
php-mbstring \
php-mysql \
php-odbc \
php-opcache \
php-pgsql \
php-phpdbg \
php-pspell \
php-readline \
php-recode \
php-soap \
php-snmp \
php-sqlite3 \
php-sybase \
php-tidy \
php-xmlrpc \
php-xsl \
php-zip
RUN sudo apt-get install -y libapache2-mod-php
RUN sudo apt-get update && sudo apt-get -y upgrade
VOLUME /var/www/html
COPY index.php /var/www/html
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 sh /tmp/install-informixpdo.sh
#Informix environment variables for Apache
COPY scripts/envvars.sh /tmp
RUN sudo sh /tmp/envvars.sh
RUN echo "extension=pdo_informix.so" >> /etc/php/7.2/apache2/conf.d/pdo.ini
RUN sudo echo "sqlexec 9088/tcp\nsqlexec-ssl 9089/tcp" >> /etc/services
EXPOSE 80
install-informixpdo.sh:
PDO_DIRECTORY=PDO_INFORMIX-1.3.3
PDO_FILENAME=$PDO_DIRECTORY.tgz
TMPDIR=/tmp
tar -xvf $TMPDIR/$PDO_FILENAME -C $TMPDIR/
cd $TMPDIR/$PDO_DIRECTORY
phpize && ./configure && make && make install
rm -r $TMPDIR/*
envvars.sh:
echo "INFORMIXDIR=/opt/ibm/informix
export INFORMIXDIR
DB_LOCALE=es_es.8859-1
export DB_LOCALE
" >> /etc/apache2/envvars
最佳答案
我尝试了您的dockerfile脚本,发现了一些错误。 docker build输出确实显示了解压缩和编译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
我更改了构建模块的脚本,因此在运行配置之前先设置INFORMIXDIR。
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”来创建软链接(soft link)。
这些是我更改的两个文件:
---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
....
PHP与apache config一起使用时会加载模块:
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”文件中添加软链接(soft link)创建和导出INFORMIXDIR。
编辑:
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#
关于php - 如何在Docker中使用php 7.2和pdo_informix制作图像?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51939425/