Участник:Lit-uriy/oci8

Перейти к: навигация, поиск


Введение


Это mini-howto по сборке модуля расширения oci8 для PHP, чтобы подключаться к Оракл.

Подтверждения и требования для каждой процедуры свои.

Шаблон:Susedoc:Note

Подтверждения


  • Использование Pear для сборки oci8
Оригинальный автор : Michael Galloway (mgx_at_ornl.gov)
Оригинальная ссылка : http://lists.suse.com/archives/suse-oracle/2007-Apr/0005.html
Эта процедура протестирована на платформе x86_32 и x86_64 используя openSuSE-10.2

Требования


  • Использование Pear для сборки oci8 :: необходимое ПО
Список ПО который должен быть установлен предварительно:
(Это ПО может быть найдено в openSuSE-10.2 CD/DVD/repos)
  • autoconf
  • php5-5.2.0-12
  • apache2-mod_php5-5.2.0-12
  • php5-pdo-5.2.0-10
  • php5-devel-5.2.0-12
  • php5-pear-5.2.0-12

Процедуры


Использование Pear для сборки oci8


ok, for grins i decided to try and get the php oci8 extension to build and load via pear/pecl. seems to go ok, here is a mini how-to all done with openSuSE 10.2 (x86_64 in this case). with both instant client and regular oracle client. i like this approach, i can keep the default rpm php install for the most part.

The following step must be running as root user.

установка необходимых пакетов php/pear rpms


i assume that you have been installed all needed software in prerequisites sections. if you do not know how to install software, read this tutorial YaST_Software_Management, it's quite easy.

установка "oracle instant client zips"


Замечание: If you have oracle server and Apache/php in one machine, skip this step and go to the next section. This section is only for people who need connected to different Oracle server machine

  • Download instant client for Oracle, here, based on your machine, x86 or x86_64, or others than that.
  • Let say that you save or copying them in /opt/oracle/ directories
  • распакуйте instant client library и sdk
 $ cd /opt/oracle
 $ unzip instantclient-basic-linux-*.zip
 $ unzip instantclient-sdk-linux-*.zip 
  • after unzip you will get directory contents like this,
$ pwd
/opt/oracle/instantclient_10_2
$ ls -l
total 99900
-r--r--r-- 1 root root 1600090 2006-12-20 10:35 classes12.jar
-rwxr-xr-x 1 root root 66545 2006-12-20 10:35 genezi
lrwxrwxrwx 1 root root 17 2007-04-03 12:11 libclntsh.so -> libclntsh.so.10.1
-rwxr-xr-x 1 root root 20870419 2006-12-20 10:35 libclntsh.so.10.1
-rwxr-xr-x 1 root root 3808761 2006-12-20 10:35 libnnz10.so
-rwxr-xr-x 1 root root 1664148 2006-12-20 10:35 libocci.so.10.1
-rwxr-xr-x 1 root root 72456247 2006-12-20 10:35 libociei.so
-rwxr-xr-x 1 root root 137905 2006-12-20 10:35 libocijdbc10.so
-r--r--r-- 1 root root 1545954 2006-12-20 10:35 ojdbc14.jar
drwxr-xr-x 4 root root 4096 2006-12-20 10:35 sdk 
  • make softlink for libclntsh.so.10.1
 $ cd /opt/oracle/instantclient_10_2
 $ ln -s libclntsh.so.10.1 libclntsh.so

настройка окружения Оракл


Note: If you want to install oci8 in different machine other than your oracle server, skip this step.

If you want to install oci8 in oracle server, the same machine where you installed oracle database and Apache/PHP, you must follow this step.

  • first test whether the ORACLE_HOME is exist
 $ echo $ORACLE_HOME
if above command print an output to some directory, skip this step.
  • if the first step does not print output, set ORACLE_HOME to the directory where you installed oracle database, i will assume that you using bash as console.
 $ ORACLE_HOME=/path/to/oracle/database/server
 $ export ORACLE_HOME

Сборка/установка/включение модуля oci8


  • Let say you save or copying them in /opt/oracle directories.
  • follow this command,
 $ cd /opt/oracle
 $ pear5 install oci8-1.2.3.tgz
above command will print an output,
...
10 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Please provide the path to ORACLE_HOME dir. Use 'instantclient,/path/to/instant/client/lib'
if you're compiling against Oracle Instant Client [autodetect] :
oci8 installation will ask you where the path instantclient directory. If you using instantclient fill them with directories where you unzip instantclient in previous section. i.e:
 instantclient,/opt/oracle/instantclient_10_2
if you using oracle server, and have set ORACLE_HOME environment, just press enter
  • and then, building continues ...
building in /var/tmp/pear-build-root/oci8-1.2.3
running: /tmp/pear/cache/oci8-1.2.3/configure --with-oci8=instantclient,/opt/instantclient_10_2
checking for grep that handles long lines and -e... /usr/bin/grep

.......

/bin/sh /var/tmp/pear-build-root/oci8-1.2.3/libtool --mode=install cp ./oci8.la 
/var/tmp/pear-build-root/oci8-1.2.3/modules
cp ./.libs/oci8.so /var/tmp/pear-build-root/oci8-1.2.3/modules/oci8.so
cp ./.libs/oci8.lai /var/tmp/pear-build-root/oci8-1.2.3/modules/oci8.la
PATH="$PATH:/sbin" ldconfig -n /var/tmp/pear-build-root/oci8-1.2.3/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /var/tmp/pear-build-root/oci8-1.2.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.
(It is safe to ignore warnings about tempnam and tmpnam).

running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-oci8-1.2.3" install
Installing shared extensions: 
/var/tmp/pear-build-root/install-oci8-1.2.3/usr/lib64/php5/extensions/running:
find "/var/tmp/pear-build-root/install-oci8-1.2.3" -ls
901127 4 drwxr-xr-x 3 root root 4096 Apr 3 13:59 /var/tmp/pear-build-root/install-oci8-1.2.3
901156 4 drwxr-xr-x 3 root root 4096 Apr 3 13:59 /var/tmp/pear-build-root/install-oci8-1.2.3/usr
901157 4 drwxr-xr-x 3 root root 4096 Apr 3 13:59 
/var/tmp/pear-build-root/install-oci8-1.2.3/usr/lib64
901158 4 drwxr-xr-x 3 root root 4096 Apr 3 13:59 
/var/tmp/pear-build-root/install-oci8-1.2.3/usr/lib64/php5
901159 4 drwxr-xr-x 2 root root 4096 Apr 3 13:59 
/var/tmp/pear-build-root/install-oci8-1.2.3/usr/lib64/php5/extensionsld process completed 
successfully
Installing '/var/tmp/pear-build-root/install-oci8-1.2.3//usr/lib64/php5/extensions/oci8.so'
install ok: channel://pecl.php.net/oci8-1.2.3
You should add "extension=oci8.so" to php.ini 
  • edit php.ini, using your favorite editor, add "extension=oci8.so"
 $ cd /etc/php5/apache2/
 $ emacs php.ini
and another php.ini in cli directory
 $ cd /etc/php5/cli/
 $ emacs php.ini
  • set LD_LIBRARY_PATH to the instantclient directory for apache
 $ LD_LIBRARY_PATH=/opt/oracle/instantclient_10_2
if you are using oracle server it should be like this
 $ LD_LIBRARY_PATH=$ORACLE_HOME/lib
  • restart apache2
 $ rcapache2 restart

Проверка установки oci8


  • verify oci8 is enabled with a phpinfo script:
 $ php /usr/share/doc/packages/php5/test.php5 | grep oci8
oci8
oci8.default_prefetch => 10 => 10
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => 0 => 0
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
  • verify connection to remote 10g2 db. Write some script for php to check connection to database. This is the simple-example template, edit "OCILogon" and "$query" to meet your database user and table.
<?php

$conn = OCILogon("dbuser", "dbpasswd", "//dbserver.host.net/DB");

$query = 'select table_name from user_tables';

$stid = OCIParse($conn, $query);
OCIExecute($stid, OCI_DEFAULT);
 while ($succ = OCIFetchInto($stid, $row)) {
    foreach ($row as $item) {
      echo $item." ";
    }
    echo "<br>\n";
 }

 OCILogoff($conn);

 ?>
then run phpdb2.php script
 $ php phpdb2.php
  • done ...

Заключение


For impatient and advanced user:

 $ unzip instantclient-basic-linux-x86-64-10.2.0.3-20070103.zip
 $ unzip instantclient-sdk-linux-x86-64-10.2.0.3-20070103.zip 
 $ pear5 install http://pecl.php.net/get/oci8 
 $ LD_LIBRARY_PATH=/path/to/instantclient/or/oracle/server/lib
 $ export LD_LIBRARY_PATH
 $ echo "extension=oci8.so" >> /etc/php5/apache2/php.ini
 $ echo "extension=oci8.so" >> /etc/php5/cli/php.ini
 $ rcapache2 restart

Ссылки





rvJJax 03:33, 29 May 2007 (UTC)