如何在 Docker 中使用 php 7.2 和 pdo_informix 制作图像?
How can i make image with php 7.2 and pdo_informix in Docker?
我正在尝试使用 apache2 在 docker 中创建图像,php7.2 使用 pdo_informix,但我没有成功,我只是没有看到启用的扩展而且我不知道我是否做错了一步。
我在以下存储库中分享到目前为止的内容:
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
安装-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-php-ext-install
命令安装php
扩展或模块。如果你使用 reguler apt-get install
命令,你应该添加步骤来启用它。请参阅下面的示例,如何使用命令:
FROM php:7.2-fpm
RUN apt-get update && apt-get install -y wget curl libxml2-dev libssl-dev zlib1g-dev apt-transport-https lsb-release ca-certificates \
&& wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
&& echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list \
&& docker-php-ext-install mbstring iconv xml pdo_mysql phar zip \
docker-php-ext-install
将自动安装并启用扩展。希望对你有帮助。
我尝试了您的 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
我更改了构建模块的脚本,以便在运行配置之前设置 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#
所以我在 docker 文件中添加了一个 "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
....
PHP 使用 apache 配置加载模块:
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' 文件中添加软链接创建和导出 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:7.2-apache
图像中设法获得了受 Joan Rivera's example 启发的容器:
https://github.com/vctls/docker_php_pdo_informix
我刚刚在遗留 Informix 7.2 数据库上成功测试了它。
我从 the IBM wbesite.
获得了 Linux x86-64 的客户端 SDK 版本 4.10 FC9DE
一旦你的环境变量正确,设置就非常简单。
我在编译 PDO_Informix 1.3.3 PECL 扩展时收到了一些警告,但它仍然有效。
我正在尝试使用 apache2 在 docker 中创建图像,php7.2 使用 pdo_informix,但我没有成功,我只是没有看到启用的扩展而且我不知道我是否做错了一步。
我在以下存储库中分享到目前为止的内容: 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
安装-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-php-ext-install
命令安装php
扩展或模块。如果你使用 reguler apt-get install
命令,你应该添加步骤来启用它。请参阅下面的示例,如何使用命令:
FROM php:7.2-fpm
RUN apt-get update && apt-get install -y wget curl libxml2-dev libssl-dev zlib1g-dev apt-transport-https lsb-release ca-certificates \
&& wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
&& echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list \
&& docker-php-ext-install mbstring iconv xml pdo_mysql phar zip \
docker-php-ext-install
将自动安装并启用扩展。希望对你有帮助。
我尝试了您的 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
我更改了构建模块的脚本,以便在运行配置之前设置 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#
所以我在 docker 文件中添加了一个 "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
....
PHP 使用 apache 配置加载模块:
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' 文件中添加软链接创建和导出 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:7.2-apache
图像中设法获得了受 Joan Rivera's example 启发的容器:
https://github.com/vctls/docker_php_pdo_informix
我刚刚在遗留 Informix 7.2 数据库上成功测试了它。
我从 the IBM wbesite.
获得了 Linux x86-64 的客户端 SDK 版本 4.10 FC9DE
一旦你的环境变量正确,设置就非常简单。
我在编译 PDO_Informix 1.3.3 PECL 扩展时收到了一些警告,但它仍然有效。