gpt4 book ai didi

php - 我如何在 Docker 中使用 php 7.2 和 pdo_informix 制作图像?

转载 作者:行者123 更新时间:2023-12-02 18:29:19 35 4
gpt4 key购买 nike

我正在尝试使用 apache2 在 docker 中创建图像,使用 pdo_informix 在 php7.2 中创建图像,但我没有成功,我只是没有看到启用的扩展,我不知道我是否做错了一步。

我在以下存储库中分享到目前为止的内容: here

Docker 文件:

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/*

环境变量.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
....

使用 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”文件中添加软链接(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/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com