Search code examples
phpdockerubuntuinformixpecl

How can i make image with php 7.2 and pdo_informix in Docker?


I am trying to create an image in docker with apache2, php7.2 with pdo_informix, but I have not been successful, I just do not see the extension enabled and I do not know if I'm doing a wrong step.

I share what I have so far in the following repository: 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

Solution

  • I tried your dockerfile script and found some errors. The docker build output did show traces on unpacking and compiling the PDO module: but was failing with an error during the PDO configure:

    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
    

    I changed the script that builds the module so INFORMIXDIR is set before it runs the configure.

    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
    

    Again it was failing somewhere else. Looking at the module build file, it expects the module in the following directories:

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

    but in the IBM docker image, that file is in:

    root@faf18c3c0ef5:/usr/include# find ./ -name php_pdo_driver.h
    ./php/20170718/ext/pdo/php_pdo_driver.h
    root@faf18c3c0ef5:/usr/include#
    

    So I added a "ln -s" to the dockerfile to create the softlink. These are the two files I altered are:

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

    and

    --- 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
    ...
    -------------
    

    With those changes I get the module compiled and installed when doing the "docker build" command

    ....
    ....
    ----------------------------------------------------------------------
    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 using with the apache config loads the module:

    root@99d4150d07ed:/# php -c /etc/php/7.2/apache2/conf.d/pdo.ini -m | grep inform
    ix
    pdo_informix
    root@99d4150d07ed:/#
    

    And a simple connection, also appears to work without issues:

    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:/#
    

    You could just add the softlink creation and the export INFORMIXDIR in the 'install-informixpdo.sh' file.

    EDIT:

    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#