Wednesday, July 21, 2010

Installation of Db2 Client On linux & Compilation of Db2 with PHP


To connect database DB2 through PHP & Compilation of PHP with DB2
Step 1 :
1> Download the client ADCL (Application Development Client 8.1.2.156)
Install runtime client also


Download Location:
http://www-01.ibm.com/support/docview.wss?rs=71&uid=swg21256051

Installation of ADCL(Following command will be used for installation purpose)
1 Go to the folder where the ADCL has been downloaded, untar it
Shell > tar -xf FP18_MI00291_ADCL_DB2.tar

Go to the folder & run the following command
Shell > ./db2_install –p DB2.ADCL

It will install the ADCL.
Step 2 > Instance Creation on the application server .generally thi
Then Ask your DBA to set instance on your Application server
Task is performed y the DBA . if DBA is not available then progarammer can also perform the same task . Documentation for the programmer is provided in the attachement.

After finishing the creation of the instance on the application server
Or You can follow the text file to set up the db2 instance


Once finish creating the instance & , u can check enviroment has been created like the following the attachement .I m attaching my environment please find it
Ste










Step-3>

We have created the text file in tmp directory its named bbb
Whenever we want to set up the enviroment we just run the following command
shell>. /tmp/bbb

Note :--
In any case problem occurs for installing the DB2 Client & compiling it with the PHP

So start the from step 1 to step 3 . before starting the step1 & step3 uninstall the db2 client . start everything freshly .

So I started from the beginning ,(I already had apache & PHP installation so I unstalled it Apache then recompile the php with apache with following command )

Uninstallation is very easy if you used previous installation from the source or Apache instead or rpm

So I just rename the folder of apache here for uninstallation which is in the /usr/local/apache2 so I renamed it /usr/local/apache2pre

Following is process of installation of Apache & PHP & compilation of PHP with DB2 Client .

Step -1 >
Then I downwloaded the apache (httpd2.2.11) & untar it & switch to that folder

& run the following command (remember this command is very important what parameter u r passing in that )






./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql \
--with-IBM_DB2=/opt/IBM/db2/V8.1 \
--enable-force-cgi-redirect \
--disable-cgi \
--with-xml=/usr/local \
--with-libxml-dir=/usr/local \
--with-xsl=/usr/local


Shell>Make
Shell>Make install

We have installed the Apache

Step – 2 > For Checking the apache installed properly or not
. Now that the binaries have been installed on your system you need to start the apache server.
/usr/local/apache2/bin/apachectl start
For future reference you can restart apache 2 by using the following command:
/usr/local/apache2/bin/apachectl restart
Or stop apache 2 using the following command:
/usr/local/apache2/bin/apachectl stop


8. You test this is running by using the following command on UNIX (must be on the same machine as apache):
telnet localhost 80

You should receive something like the following:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
echo


501 Method Not Implemented

Method Not Implemented


echo to /index.html.en not supported.




Apache/2.0.51 (Unix) mod_ssl/2.0.51 OpenSSL/0.9.7c Server at server7.crucialdns.com Port 80


Connection closed by foreign host.

************************optional start************************************
Have apache 2 start up automatically:
For FreeBSD add the following line to /etc/rc.local
/usr/local/apache2/bin/apachectl start
On Red Hat or Fedora 1 or 2:
Copy the apache startup script (apachectl) from the apache directory to the startup directory.
cp /usr/local/apache2/bin/apachectl /etc/init.d/
Add the following 2 lines to /etc/init.d/apachectl (after the #!/bin/sh)
# chkconfig: - 85 15
# description: Apache is a Web server used to serve HTML files and CGI.
Enable apache/httpd to startup automatically:
/sbin/chkconfig --add apachectl
************************ Optional End **********************************
After Finishing this
Step - 3> Installing PHP 5.2.9 with Apache2
1. Change directory into the PHP source directory (php-5.2.9).

As Our basic purpose is to configure extension IBM_DB2 with so
Download the ibm_db2 from
http://pecl.php.net/package/ibm_db2/download/1.0
ibm_db2-1.2.1 I tried 1.2.0 u can try more stable version is 1.8.2
& copy it in the source directory there is one ext folder copy it there
U have make folder IBM_DB2 or ibm_db2
Just like this php-5.2.9/ext/IBM_DB2
php-5.2.9/ext/ibm_db2
2. Configure PHP using the ./configure command, options are as follows:
--with-mysql \
--prefix=/usr/local/apache2/php \
./buildconf --force \
./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-IBM_DB2=/opt/IBM/db2/V8.1 \
--with-config-file-path=/usr/local/apache2/php \
--with-pear=/usr/local/apache2/php/lib/php \
--enable-force-cgi-redirect \
--disable-cgi \
--with-xml \
--with-libxml-dir=/usr/local \
--with-xsl=/usr/local
Above I needed so I used above command, following are optional to make connection by other way eg unixodbc or pdo(php data objects)
--with-pdo-odbc=ibm-db2,/opt/IBM/db2/V8.1 \
--with-unixODBC \
--prefix=/usr/local/apache2/php \
Shell>Make
shell>Make install

Step 4 > Configuration of file php.ini
add followinf line in php .ini file ()
in following two line either you can a> or b> line
For My configuration I added b> line
a>extension=ibm_db2.so
b>ibm_db2.instance_name=db2inst1

Step 5>module Copying if does not exist .
5. If /usr/local/apache2/modules/libphp5.so does not exist then run the following command:
cp -p .libs/libphp4.so /usr/local/apache2/modules
Step 6>Copying the php.ini configuration file if does not exist .
6. Copy the default configuration file to the PHP config directory:
cp -p php.ini-recommended /usr/local/apache2/php/php.ini
7. Open the apache2 logfile and make sure that the following lines exist:
LoadModule php4_module modules/libphp4.so
DirectoryIndex index.html index.php
AddType application/x-httpd-php php
AddType application/x-httpd-php-source phps
^ This one adds colouring to PHP syntax, not required
If these do not exist in your apache config files (/usr/local/apache2/conf/httpd.conf) then add then so as to allow PHP to function correctly.
8. Restart apache:
/usr/local/apache2/bin/apachectl restart
9. Check that PHP and apache are running, create the following directory in your html directory:
info.php







Check that ibm_db2 extension is enabled or not








Then try running the following script
$database = 'fdmdb1t';
$user = 'fdmusr1t';
$password = '*******';
//$port = 50000;
$conn = db2_connect($database, $user, $password);
if($conn){
echo "Connection succeeded.";
db2_close($conn);
}else{
echo "Connection failed.";}

That’s all ..thanks
Regards
Pradip
Pradip.bhoge@gmail.com

No comments:

Post a Comment