Apache 2.4 + PHP 5.4 + PDO_IBM on Ubuntu 12.04 HOWTO
This simple HOWTO will guide you about how to setup Apache2.4 + PHP5.4 + PDO_IBM from sketch. Compile all package from tarball can give you the maximum flexibility of functionality, e.g. you can enable both mysql/mysqli/pgsql/oci8/pdo_mysql/pdo_pgsql/pdo_oci/pdo_ibm within single installation.
Before start, I will assume you have Ubuntu 12.04 and DB2 Express-C 10.1 installed correctly, which will not detail within this document. If you really need some help for that, please refer to my other article for more indeed guideline.
Install required packages
Debian apt-get can give us a great hand when prepare system for building custom packages from sketch. Just simply run this command:
aptitude update && \ aptitude -y full-upgrade && \ aptitude -y install git vim libmcrypt-dev && \ apt-get -y build-dep apache2 php5
Install Apache2.4
Get Apache2.4 source from GIT, compile, and install it:
cd /usr/local/src git clone --branch 2.4.x https://github.com/apache/httpd.git httpd-2.4.x cd httpd-2.4.x git clone https://github.com/apache/apr.git srclib/apr ./buildconf ./configure -enable-modules=all --with-included-apr --enable-mpm=worker --enable-suexec --enable-rewrite make make install
You should retouch the Apache configuration. Edit /usr/local/apache2/conf/httpd.conf and take the similar change as below:
User www-data
Group www-data
ServerAdmin root@localhost.localdomain
DocumentRoot "/var/www"
<Directory "/var/www">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
Also need to ensure Apache have correct privilege to access its document root:
chown -Rf www-data:www-data /var/www
Symbolic link all Apache execute binaries to /usr/local/bin:
ln -s /usr/local/apache2/bin/* /usr/local/bin/
Remove the /etc/init.d/apache2 and replace it as a symbolic link to /usr/local/bin/apachectl:
rm -rf /etc/init.d/apache2 ln -s /usr/local/bin/apachectl /etc/init.d/apache2
Ensure your Apache will start automatically during system boot:
update-rc.d -f apache2 remove update-rc.d -f apache2 defaults 91 09
Restart Apache and so let all changes take effect:
/etc/init.d/apache2 stop /etc/init.d/apache2 start
Try to access http://localhost.localdomain/index.html and check if message appear.
Install PHP5.4
First of all, unpack the PHP tarball:
cd /usr/local/src/ git clone --branch PHP-5.4 https://github.com/php/php-src.git php-5.4.x cd /usr/local/src/php-5.4.x/ext/ wget http://pecl.php.net/get/PDO_IBM-1.3.3.tgz gzip -d < PDO_IBM-1.3.3.tgz | tar -xvf - mv PDO_IBM-1.3.3 pdo_ibm wget http://pecl.php.net/get/APC-3.1.13.tgz gzip -d < APC-3.1.13.tgz | tar -xvf - mv APC-3.1.13 apc cd /usr/local/src/php-5.4.x/ rm -rf configure ./buildconf --force
You should check all available parameter with:
./configure --help
Before start the configuration, I would like to give you some suggested combination of parameters. E.g.:
--enable-bcmath \ --enable-calendar \ --enable-dba \ --enable-exif \ --enable-ftp \ --enable-mbstring \ --enable-shmop \ --enable-sigchild \ --enable-soap \ --enable-sockets \ --enable-sqlite-utf8 \ --enable-sysvmsg \ --enable-wddx \ --enable-zip \ --with-apxs2=/usr/local/apache2/bin/apxs \ --with-bz2 \ --with-config-file-path=/usr/local/apache2/conf \ --with-curl \ --with-gd \ --with-gettext \ --with-mcrypt \ --with-mysql \ --with-mysqli \ --with-openssl \ --with-pdo-mysql \ --with-pdo-pgsql \ --with-pgsql \ --with-xmlrpc \ --with-zlib \Moreover, IBM_DB2 and PDO_IBM should configuration as (assume you have install DB2 under /home/db2inst1):
--with-ibm-db2=/home/db2inst1/sqllib \ --with-pdo-ibm=/home/db2inst1/sqllib \
So the complete PHP5.3 configuration command with IBM_DB2 + PDO_IBM should be:
. /home/db2inst1/sqllib/db2profile ./configure \ --enable-apc \ --enable-bcmath \ --enable-calendar \ --enable-dba \ --enable-exif \ --enable-ftp \ --enable-mbstring \ --enable-shmop \ --enable-sigchild \ --enable-soap \ --enable-sockets \ --enable-sysvmsg \ --enable-wddx \ --enable-zip \ --with-apxs2=/usr/local/apache2/bin/apxs \ --with-bz2 \ --with-config-file-path=/usr/local/apache2/conf \ --with-curl \ --with-gd \ --with-gettext \ --with-mcrypt \ --with-mysql-sock=/var/run/mysqld/mysqld.sock \ --with-openssl \ --with-pdo-ibm=/home/db2inst1/sqllib \ --with-pdo-mysql \ --with-pdo-pgsql \ --with-xmlrpc \ --with-zlib
Next, build and install the PHP5:
make && \ make test && \ make install
Copy PHP's supplied initialization file:
cp /usr/local/src/php-5.4.x/php.ini-development /usr/local/apache2/conf/php.ini sed -i 's/^;\(date\.timezone\) =\s*$/\1 = "Asia\/Hong_kong"/g' /usr/local/apache2/conf/php.ini sed -i 's/^\(memory_limit\) = .*$/\1 = 256M/g' /usr/local/apache2/conf/php.ini sed -i 's/^\(post_max_size\) = .*$/\1 = 32M/g' /usr/local/apache2/conf/php.ini sed -i 's/^\(upload_max_filesize\) = .*$/\1 = 32M/g' /usr/local/apache2/conf/php.ini sed -i 's/^\(max_execution_time\) = .*$/\1 = 3600/g' /usr/local/apache2/conf/php.ini sed -i 's/^\(max_input_time\) = .*$/\1 = 7200/g' /usr/local/apache2/conf/php.ini
Create a PHP configuration file for Apache as /usr/local/apache2/conf/extra/httpd-php5.conf and add the following lines:
# # This next section will call PHP for .php, .phtml, and .phps files # AddType application/x-httpd-php .php AddType application/x-httpd-php .phtml AddType application/x-httpd-php-source .phps # # This is the directory containing php.ini # PHPIniDir "/usr/local/apache2/conf"
Retouch /usr/local/apache2/conf/httpd.conf and add this line to the end of file:
Include conf/extra/httpd-php5.conf
If a LoadModule line was not already inserted by the PHP install, add it too:
LoadModule php5_module modules/libphp5.so
Also update the DirectoryIndex:
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml
</IfModule>
Create a testing file as /var/www/phpinfo.php with below content:
<?php print phpinfo(); ?>
Restart your Apache and test your PHP setup with http://localhost.localdomain/phpinfo.php
DB2 specific fine tune
By default, Apache's user account and user group don't have privilege to access DB2's resources, so we will need some hack:
adduser www-data db2iadm1
Next, Apache don't have the idea about DB2 variables, so we need to specify for it. Edit /usr/local/apache2/bin/envvars and add the following lines at the end of file:
. /home/db2inst1/sqllib/db2profile
In case of checking PDO_IBM, create /var/www/pdo_ibm.php with following content, access http://localhost.localdomain/pdo_ibm.php:
<?php
$db_conn = new PDO('ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=SAMPLE;', 'db2inst1', 'CHANGE');
$cmdstr = 'SELECT "LASTNAME", "SALARY" FROM "EMPLOYEE"';
$stmt = $db_conn->query($cmdstr);
$results = $stmt->fetchAll();
$stmt = $db_conn->query("SELECT COUNT(*) AS nrows FROM ($cmdstr)");
$nrows = $stmt->fetch(PDO::FETCH_OBJ)->NROWS;
echo "<html><head><title>IBM DB2 PHP Test</title></head><body>";
echo "<center><h2>IBM DB2 PHP Test</h2><br>";
echo "<table border=1 cellspacing='0' width='50%'>\n<tr>\n";
echo "<td><b>Name</b></td>\n<td><b>Salary</b></td>\n</tr>\n";
for ($i = 0; $i < $nrows; $i++ ) {
echo "<tr>\n";
echo "<td>" . $results[$i]["LASTNAME"] . "</td>";
echo "<td>$ " . number_format($results[$i]["SALARY"], 2). "</td>";
echo "</tr>\n";
}
echo "<tr><td colspan='2'> Number of Rows: $nrows</td></tr></table><br>";
echo "<em>If you see data, then it works!</em><br>";
echo "</center></body></html>\n";
?>
Sample output:
- hswong3i's blog
- Add new comment
- 6110 reads



Comments
Excellent guide! I love the
Excellent guide! I love the details you mention. Thanks!
Reply to
The concept of your blog is extremely fresh, I'm sure that the readers that encounter your blogs will take a lot from your content and advice.
Add new comment