PHP Informix PDO Driver in RHEL 8

This post could be also be named: “how to implement a LAIP stack in RHEL/CentOS 8”. LAIP stands for Linux, Apache, Informix and PHP but there are tons of documentation about how to install LAMP stack in RHEL and I want to focus in Informix implementation.

Install LAMP stack

I assume you’re starting from a RHEL 8 minimal installation, so you need to install all packages to enable Apache HTTP Server and PHP. To install required packages, execute:

yum -y install httpd php php-cli php-fpm php-pdo php-mysqlnd php-zip php-gd php-mbstring \
               php-curl php-xml php-pear php-bcmath php-json mariadb-server

Previous command install packages, but doesn’t enable or start the services. You need to enable services to start them each time the server is rebooted. Notice that, in RHEL 8, PHP is executed by a separate daemon named php-fpm and started also as a service. Execute:

systemctl enable --now httpd
systemctl enable --now php-fpm

Last step is to configure firewall to allow external connections to HTTP/HTTPS ports:

firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload

Now you should be able to connect to http server and see the welcome page, by opening a browser and pointing to your server IP:

http://[my server ip]

Install Informix Client SDK

Informix Client SDK for linux includes dbaccess and other programs which requires ncurses library. In order to install Informix Client SDK you need to install ncurses compatibility library in advance:

yum -y install ncurses-compat-libs

Next, in order to download Informix C-SDK package, go to IBM website https://www.ibm.com/products/informix/developer-tools and download Informix Client SDK Developer Edition for Linux x86_64 Versión 4.50.FC2

Copy the downloaded tar file to your RHEL 8 Server and extract it in a temporary folder

tar xvf ibm.csdk.4.50.FC2.LNX.tar

Then connect as root and execute installation program:

./installclientsdk

We assume, you will install the Informix Client SDK in default folder /opt/IBM/Informix_Client-SDK. If not, just change this folder in following steps to accomodate to your Informix C-SDK installation.

Install Informix PHP PDO Driver

Informix PHP PDO Driver is only available in source code, so you will need to compile it. Doing that requires some development packages from RHEL 8:

yum -y install php-devel make

Next, as user root, download, compile and install PDO Driver:

wget https://pecl.php.net/get/PDO_INFORMIX-1.3.3.tgz
tar xzvf PDO_INFORMIX-1.3.3.tgz
cd PDO_INFORMIX-1.3.3
export INFORMIXDIR=/opt/IBM/Informix_Client-SDK
phpize
./configure --with-pdo-informix=$INFORMIXDIR
make
make install

If everything worked properly, you should have a pdo_informix.so file in /usr/lib64/php/modules/pdo_informix.so

2023-08-08 Edit: New versión 1.3.6 of driver is available. This version fixes some small issues and adds support for PHP 8.1. You can download it at https://pecl.php.net/get/PDO_INFORMIX-1.3.6.tgz

Configure Informix PHP PDO Driver

Now, you need to configure PHP and enable loading of pdo_informix extension. create a new file /etc/php.d/30-pdo_informix.ini and insert “extension=pdo_informix” into it:

cat > /etc/php.d/30-pdo_informix.ini <<EOF
extension=pdo_informix
EOF

By default, Informix PDO Driver requires INFORMIXDIR environment variable pointing to folder where Informix Client SDK has been installed, So, next step is to change default PHP behaviour not allowing to pass environment variables to PHP programs or modules:

Edit /etc/php-fpm.d/www.conf  and add or uncomment line:  clear_env = no

Final configuration step is to pass INFORMIXDIR environment variable to PHP daemon so pdo_informix extension inherits it and will be able to load Informix libraries properly.

To set the INFORMIXDIR environment variable for the PHP daemon, run systemctl edit php-fpm.service and enter:

[Service]
Environment=INFORMIXDIR=/opt/IBM/Informix_Client-SDK

This will create or edit a file named /etc/systemd/system/php-fpm.service.d/override.conf, but this is only for informational pourposes as this is how systemd works.

For you reference, configuring environment variables in RHEL 7 should be done in other way: you should edit file /etc/sysconfig/httpd and add configuration of variables there:

vi /etc/sysconfig/httpd

Add:

## INFORMIX PDO
INFORMIXDIR=/opt/IBM/Informix_Client-SDK
DB_LOCALE=es_ES.utf8
CLIENT_LOCALE=es_Es.utf8
LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/c++:$INFORMIXDIR/lib/client:$INFORMIXDIR/lib/dmi

Configure SELinux

Security-Enhanced Linux (SELinux) is a Linux kernel security module that provides a mechanism for supporting access control security policy. RHEL 8 has SELinux enabled by default.

When running a PHP script from Apache, the PHP, the script is run as user daemon that not has root uid. The Linux security enhancement feature (SELinux) can cause a permission problem when connecting to the Informix database server.

You can see this problems when running PHP code within a browser using an http server i.e. Apache, then you will encounter a -908 error.

Easiest way to override this problem is to disable SELinux in this server. To disable SELinux modify the /etc/selinux/config file and set:

SELINUX=disabled

Reboot your server and then all is done: You have your Apache and PHP services being able to connect to Informix Databases thru Informix PDO Drivers

Test Informix PDO Driver

In order to test your informix PDO Driver, you can create a new php file in /var/www/html and use it from your browser. We show you an example of how this file can be:

vi /var/www/html/ifxtest.php

And add this content, changing Informix parameters to match your installation:

<?php
$dbname='test_db';
$dbuser = 'ifmxuser';
$dbpass = 'Inf4mixPass';

$dns = "informix:host=192.168.1.50;service=9888;database=$dbname;server=ol_myifmxserver;protocol=onsoctcp";
$dns .= ";db_locale=en_us.utf8;EnableScrollableCursors=1;client_locale=en_us.utf8";

$conexion = new PDO($dns, $dbuser, $dbpass);

$sql = "SELECT FIRST 4 * FROM test_table";
$prep = $conexion->prepare($sql);
$prep->execute();
$result = $prep->fetchAll(PDO::FETCH_ASSOC);

echo "<pre>";
var_dump($result);
echo "</pre>";
?>

And open your browser and enter the url pointing to your new file:

http://[my server ip]/ifxtest.php

You should wee your table contents in the browser.

Vicente Salvador Cubedo

IIUG Board Member

Published
Categorized as Blog

By Vicente Salvador

Board member since 2014, a user since 1989 and Informix fan. I'am software architect which allow me to combine technical and business skills.

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *