Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and Informix on Debian - how to install/configure the PDO

Tags:

php

pdo

informix

This question seems to be asked quite a bit and the answer seems to change with time. I've spent the weekend getting the IBM Client SDK for Informix working on Debian (because most directions on the process are lacking, so this took a weekend to sort out.) I can connect and run queries to a remote Informix server with isql now - no problem. Now I need PHP to connect so that I can render output to apache. This syntax;

<?php
try {
    $dbh = new PDO("informix:DSN=InformixDB", "username", "password");
    }
catch (PDOException $e)
    {
    echo $e->getMessage();
    }
 ?>

Produces a "could not find driver" error on the web page (this is generic syntax - I fill in the information of course). From what I have read, a php Informix PDO driver needs to be installed, but I can't find a how-to. It used to be that it was install with PECL(?), now it's not. Does someone know? I have installed the following PHP packages;

php5 php5-dev php5-cli

Any help is very much appreciated.

like image 579
Kimomaru Avatar asked Nov 11 '13 14:11

Kimomaru


Video Answer


1 Answers

This answer is how I configure and installed Informix PDO at OpenSuse 12.3
I think they should apply to Debian too, except the apache set.
If have some detail about Debian to add, please fell free to edit or add at the comment.

Observation : Nothing of ODBC was used here... only pure PDO...

All was executed with user root
1) download last version of PDO

$ mkdir pdo
$ cd pdo
$ wget http://pecl.php.net/get/PDO_INFORMIX-1.3.1.tgz
--2013-11-12 12:21:51--  http://pecl.php.net/get/PDO_INFORMIX-1.3.1.tgz
Resolving pecl.php.net (pecl.php.net)... 76.75.200.106
Connecting to pecl.php.net (pecl.php.net)|76.75.200.106|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 67566 (66K) [application/octet-stream]
Saving to: `PDO_INFORMIX-1.3.1.tgz'

100%[=====================================================================================================================================================================================>] 67,566      --.-K/s   in 0.04s

2013-11-12 12:21:52 (1.57 MB/s) - `PDO_INFORMIX-1.3.1.tgz' saved [67566/67566]

2) uncompress

$ tar zxf PDO_INFORMIX-1.3.1.tgz
$ cd PDO_INFORMIX-1.3.1/

3) set your INFORMIXDIR

$ export INFORMIXDIR=/myifx/csdk

3) execute phpize

$ phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
configure.in:3: warning: prefer named diversions
configure.in:3: warning: prefer named diversions

3) execute the ./configure

$ ./configure
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... -std=gnu99
checking for gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu99
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for icc... no
checking for suncc... no
checking whether gcc -std=gnu99 and cc understand -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib
checking for PHP extension directory... /usr/lib64/php5/extensions
checking for PHP installed headers prefix... /usr/include/php5
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... gawk
checking for Informix driver for PDO... yes, shared
checking for PDO includes... configure: error: Cannot find php_pdo_driver.h.

Ooops.. this is bug at Opensuse, not sure if can occur to Debian too...
Need to correct the path of php_pdo_driver.h at ./configure and rerun.

$ grep php_pdo_driver.h configure
  if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then
  elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then
  elif test -f $prefix/include/php/ext/pdo/php_pdo_driver.h; then
    as_fn_error $? "Cannot find php_pdo_driver.h." "$LINENO" 5

$ locate php_pdo_driver.h
/usr/include/php5/ext/pdo/php_pdo_driver.h


$ sed -ie 's,include/php/ext/pdo/php_pdo_driver.h,include/php5/ext/pdo/php_pdo_driver.h,g' configure

$ ./configure
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... -std=gnu99
checking for gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu99
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for icc... no
checking for suncc... no
checking whether gcc -std=gnu99 and cc understand -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib
checking for PHP extension directory... /usr/lib64/php5/extensions
checking for PHP installed headers prefix... /usr/include/php5
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... gawk
checking for Informix driver for PDO... yes, shared
checking for PDO includes... /usr/include/php/ext
checking for includes and libraries... /myifx/informix
checking Informix version... 370
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc -std=gnu99... /usr/x86_64-suse-linux/bin/ld
checking if the linker (/usr/x86_64-suse-linux/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/x86_64-suse-linux/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) gawk
checking command to parse /usr/bin/nm -B output from gcc -std=gnu99 object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc -std=gnu99 supports -fno-rtti -fno-exceptions... no
checking for gcc -std=gnu99 option to produce PIC... -fPIC -DPIC
checking if gcc -std=gnu99 PIC flag -fPIC -DPIC works... yes
checking if gcc -std=gnu99 static flag -static works... no
checking if gcc -std=gnu99 supports -c -o file.o... yes
checking if gcc -std=gnu99 supports -c -o file.o... (cached) yes
checking whether the gcc -std=gnu99 linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands

4) compile the PDO

$ make
/bin/sh /root/pdo/PDO_INFORMIX-1.3.1/libtool --mode=compile gcc -std=gnu99 -I/usr/include/php/ext -I. -I/root/pdo/PDO_INFORMIX-1.3.1 -DPHP_ATOM_INC -I/root/pdo/PDO_INFORMIX-1.3.1/include -I/root/pdo/PDO_INFORMIX-1.3.1/main -I/root/pdo/PDO_INFORMIX-1.3.1 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/myifx/csdk/incl/cli -I/myifx/csdk/incl/esql  -DHAVE_CONFIG_H  -g -O2   -c /root/pdo/PDO_INFORMIX-1.3.1/pdo_informix.c -o pdo_informix.lo
libtool: compile:  gcc -std=gnu99 -I/usr/include/php/ext -I. -I/root/pdo/PDO_INFORMIX-1.3.1 -DPHP_ATOM_INC -I/root/pdo/PDO_INFORMIX-1.3.1/include -I/root/pdo/PDO_INFORMIX-1.3.1/main -I/root/pdo/PDO_INFORMIX-1.3.1 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/myifx/csdk/incl/cli -I/myifx/csdk/incl/esql -DHAVE_CONFIG_H -g -O2 -c /root/pdo/PDO_INFORMIX-1.3.1/pdo_informix.c  -fPIC -DPIC -o .libs/pdo_informix.o
/bin/sh /root/pdo/PDO_INFORMIX-1.3.1/libtool --mode=compile gcc -std=gnu99 -I/usr/include/php/ext -I. -I/root/pdo/PDO_INFORMIX-1.3.1 -DPHP_ATOM_INC -I/root/pdo/PDO_INFORMIX-1.3.1/include -I/root/pdo/PDO_INFORMIX-1.3.1/main -I/root/pdo/PDO_INFORMIX-1.3.1 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/myifx/csdk/incl/cli -I/myifx/csdk/incl/esql  -DHAVE_CONFIG_H  -g -O2   -c /root/pdo/PDO_INFORMIX-1.3.1/informix_driver.c -o informix_driver.lo
libtool: compile:  gcc -std=gnu99 -I/usr/include/php/ext -I. -I/root/pdo/PDO_INFORMIX-1.3.1 -DPHP_ATOM_INC -I/root/pdo/PDO_INFORMIX-1.3.1/include -I/root/pdo/PDO_INFORMIX-1.3.1/main -I/root/pdo/PDO_INFORMIX-1.3.1 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/myifx/csdk/incl/cli -I/myifx/csdk/incl/esql -DHAVE_CONFIG_H -g -O2 -c /root/pdo/PDO_INFORMIX-1.3.1/informix_driver.c  -fPIC -DPIC -o .libs/informix_driver.o
/root/pdo/PDO_INFORMIX-1.3.1/informix_driver.c: In function 'dbh_prepare_stmt':
/root/pdo/PDO_INFORMIX-1.3.1/informix_driver.c:133:3: warning: implicit declaration of function 'stmt_cleanup' [-Wimplicit-function-declaration]
/bin/sh /root/pdo/PDO_INFORMIX-1.3.1/libtool --mode=compile gcc -std=gnu99 -I/usr/include/php/ext -I. -I/root/pdo/PDO_INFORMIX-1.3.1 -DPHP_ATOM_INC -I/root/pdo/PDO_INFORMIX-1.3.1/include -I/root/pdo/PDO_INFORMIX-1.3.1/main -I/root/pdo/PDO_INFORMIX-1.3.1 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/myifx/csdk/incl/cli -I/myifx/csdk/incl/esql  -DHAVE_CONFIG_H  -g -O2   -c /root/pdo/PDO_INFORMIX-1.3.1/informix_statement.c -o informix_statement.lo
libtool: compile:  gcc -std=gnu99 -I/usr/include/php/ext -I. -I/root/pdo/PDO_INFORMIX-1.3.1 -DPHP_ATOM_INC -I/root/pdo/PDO_INFORMIX-1.3.1/include -I/root/pdo/PDO_INFORMIX-1.3.1/main -I/root/pdo/PDO_INFORMIX-1.3.1 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/myifx/csdk/incl/cli -I/myifx/csdk/incl/esql -DHAVE_CONFIG_H -g -O2 -c /root/pdo/PDO_INFORMIX-1.3.1/informix_statement.c  -fPIC -DPIC -o .libs/informix_statement.o
/bin/sh /root/pdo/PDO_INFORMIX-1.3.1/libtool --mode=link gcc -std=gnu99 -DPHP_ATOM_INC -I/root/pdo/PDO_INFORMIX-1.3.1/include -I/root/pdo/PDO_INFORMIX-1.3.1/main -I/root/pdo/PDO_INFORMIX-1.3.1 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/myifx/csdk/incl/cli -I/myifx/csdk/incl/esql  -DHAVE_CONFIG_H  -g -O2   -o pdo_informix.la -export-dynamic -avoid-version -prefer-pic -module -rpath /root/pdo/PDO_INFORMIX-1.3.1/modules  pdo_informix.lo informix_driver.lo informix_statement.lo -Wl,-rpath,/root/pdo/PDO_INFORMIX-1.3.1/. -L/root/pdo/PDO_INFORMIX-1.3.1/. -Wl,-rpath,/myifx/csdk/lib/esql -L/myifx/csdk/lib/esql -Wl,-rpath,/myifx/csdk/lib/cli -L/myifx/csdk/lib/cli -Wl,-rpath,/myifx/csdk/lib -L/myifx/csdk/lib -lifcli -lifdmr -lifsql -lifasf -lifgen -lifos -lifgls -ldl -lcrypt -lifglx
libtool: link: gcc -std=gnu99 -shared  -fPIC -DPIC  .libs/pdo_informix.o .libs/informix_driver.o .libs/informix_statement.o   -L/root/pdo/PDO_INFORMIX-1.3.1/. -L/myifx/csdk/lib/esql -L/myifx/csdk/lib/cli -L/myifx/csdk/lib -lifcli -lifdmr -lifsql -lifasf -lifgen -lifos -lifgls -ldl -lcrypt -lifglx  -O2 -Wl,-rpath -Wl,/root/pdo/PDO_INFORMIX-1.3.1/. -Wl,-rpath -Wl,/myifx/csdk/lib/esql -Wl,-rpath -Wl,/myifx/csdk/lib/cli -Wl,-rpath -Wl,/myifx/csdk/lib   -Wl,-soname -Wl,pdo_informix.so -o .libs/pdo_informix.so
libtool: link: ( cd ".libs" && rm -f "pdo_informix.la" && ln -s "../pdo_informix.la" "pdo_informix.la" )
/bin/sh /root/pdo/PDO_INFORMIX-1.3.1/libtool --mode=install cp ./pdo_informix.la /root/pdo/PDO_INFORMIX-1.3.1/modules
libtool: install: cp ./.libs/pdo_informix.so /root/pdo/PDO_INFORMIX-1.3.1/modules/pdo_informix.so
libtool: install: cp ./.libs/pdo_informix.lai /root/pdo/PDO_INFORMIX-1.3.1/modules/pdo_informix.la
libtool: finish: PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:~/bin:/sbin" ldconfig -n /root/pdo/PDO_INFORMIX-1.3.1/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /root/pdo/PDO_INFORMIX-1.3.1/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'.

5) install the PDO

$ make install
Installing shared extensions:     /usr/lib64/php5/extensions/

$ ls -ltr /usr/lib64/php5/extensions/ | tail
-rw-r--r-- 1 root root   85720 Jul 16 08:19 sqlite.so
-rw-r--r-- 1 root root   49840 Jul 16 08:19 sqlite3.so
-rw-r--r-- 1 root root   48048 Jul 16 08:19 sockets.so
-rw-r--r-- 1 root root   35760 Jul 16 08:19 xmlreader.so
-rw-r--r-- 1 root root   18928 Jul 16 08:19 tokenizer.so
-rw-r--r-- 1 root root   14864 Jul 16 08:19 sysvshm.so
-rw-r--r-- 1 root root   40224 Jul 16 08:19 zlib.so
-rw-r--r-- 1 root root  102264 Jul 16 08:19 zip.so
-rw-r--r-- 1 root root   52016 Jul 16 08:19 xmlwriter.so
-rwxr-xr-x 1 root root  164722 Nov 12 12:29 pdo_informix.so

6) Active the PDO at PHP

$ cd /etc/php5/conf.d
$ echo "extension=pdo_informix.so" > pdo_informix.ini

7) "Active" the INFORMIX variables at Apache. here, probably will be different for debian.

$ cd /etc/sysconfig/

$ tail apache2
#
# If mod_status is used, include extended information about the server, like
# CPU usage, in the status report. It is a server-wide setting, and it can cost
# some performance!
#
APACHE_EXTENDED_STATUS="off"

INFORMIXDIR=/myifx/csdk
LD_LIBRARY_PATH=/myifx/csdk/lib:/myifx/csdk/lib/esql:/myifx/csdk/lib/client:/myifx/csdk/lib/cli:$LD_LIBRARY_PATH

8) restart apache

$ systemctl restart apache2.service

9) Then I able to access using this PHP...

$ cd /srv/www/htdocs
$ cat ifx.php
<?php

$db = new PDO("informix:host=myifx_ifxhom; service=11205; database=xyz; server=idsbkp_soc; protocol=onsoctcp; EnableScrollableCursors=1", "cesar", "cesar");

print "Connection Established!\n\n";

$stmt = $db->query("select * from systables");
$res = $stmt->fetch( PDO::FETCH_BOTH );
$rows = $res[0];
echo "Table contents: $rows.\n";

?>

You can check if you apache loaded the Informix PDO with php_info : php_info pdo_informix And check if the Informix variables was recognized by apache: phpinfo environment variables Using this code:

$ cat phpinfo.php
<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>
like image 148
ceinmart Avatar answered Sep 23 '22 03:09

ceinmart