Install OCI8 dan PDO_OCI ubuntu 20.04

Kali ini saya akan sedikit berbagi pengalaman tentang instalasi extension pdo_oci di ubuntu 20.04.  Extension ini dibutuhkan jika aplikasi kita ingin membaca database oracle melalui pdo. Pertama kita siapkan senjata kita terlebih dahulu yaitu :

  1. Instantclient oracle bisa didownload di https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
  2. Pilih basic dan sdk
  3. Install aplikasi pendukung untuk compile source melalui perintah sudo apt-get install php-dev build-essential libaio1
  4. Download source oci8 di sini, saya menggunakan versi 2.2.0
  5. Download source pdo_oci extension, saya ambil dari source aslinya di PHP 7.4.6, sebenarnya versi yang terinstall di laptop saya saat ini adalah versi 7.4.5 namun gak ada masalah juga sih

Setelah semua telah siap sekarang kita lakukan instalasi, pertama kita install oci8 dulu kemudian pdo_oci.

Install OCI_8

  1. Extract instantclient basic dan sdk yang telah didowload tadi dalam satu folder, disini saya extract ke /data/master/instantclient_19_6 , selalu ingat tempat folder kira melakukan extract ini karena akan kita gunakan ketika proses instalasi OCI_8. Berikut hasil extract dalam laptop saya
  2. Extract file oci ( langkah ke-4 diatas ) hasil download tadi, letakkan dimana saja terserah. Hanya saja dalam contoh saya extract ke folder unduhan
  3. Setelah semua siap sekarang kita lakukan instalasi, masuk ke command prompt atau terminal kemudian ketikkan perintah phpize , kurang lebih jika tidak ada error tampilannya seperti dibawah ini
    ahmad@ahmad-Lenovo-ideapad-300-14ISK:~/Unduhan/oci8-2.2.0$phpize
    Configuring for:
    PHP Api Version: 20190902
    Zend Module Api No: 20190902
    Zend Extension Api No: 320190902
  4. Langkah selanjutnya ketikkan perintah sudo make install jika tidak ada error kurang lebih tampilannya akan seperti ini
    ahmad@ahmad-Lenovo-ideapad-300-14ISK:~/Unduhan/oci8-2.2.0$ sudo make install
    /bin/bash /home/ahmad/Unduhan/oci8-2.2.0/libtool --mode=link cc -DPHP_ATOM_INC -I/home/ahmad/Unduhan/oci8-2.2.0/include -I/home/ahmad/Unduhan/oci8-2.2.0/main -I/home/ahmad/Unduhan/oci8-2.2.0 -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/data/master/instantclient_19_6/sdk/include -DHAVE_CONFIG_H -g -O2 -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /home/ahmad/Unduhan/oci8-2.2.0/modules oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo oci8_failover.lo -Wl,-rpath,/data/master/instantclient_19_6 -L/data/master/instantclient_19_6 -lclntsh
    cc -shared .libs/oci8.o .libs/oci8_lob.o .libs/oci8_statement.o .libs/oci8_collection.o .libs/oci8_interface.o .libs/oci8_failover.o -L/data/master/instantclient_19_6 -lclntsh -Wl,-rpath -Wl,/data/master/instantclient_19_6 -Wl,-soname -Wl,oci8.so -o .libs/oci8.so
    creating oci8.la
    (cd .libs && rm -f oci8.la && ln -s ../oci8.la oci8.la)
    /bin/bash /home/ahmad/Unduhan/oci8-2.2.0/libtool --mode=install cp ./oci8.la /home/ahmad/Unduhan/oci8-2.2.0/modules
    cp ./.libs/oci8.so /home/ahmad/Unduhan/oci8-2.2.0/modules/oci8.so
    cp ./.libs/oci8.lai /home/ahmad/Unduhan/oci8-2.2.0/modules/oci8.la
    PATH="$PATH:/sbin" ldconfig -n /home/ahmad/Unduhan/oci8-2.2.0/modules
    ----------------------------------------------------------------------
    Libraries have been installed in:
    /home/ahmad/Unduhan/oci8-2.2.0/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.
    ----------------------------------------------------------------------
    Installing shared extensions: /usr/lib/php/20190902/
    
    
  5. Rename file libclntsh.so dalam folder instantclient kita ( sesuaikan dengan tempat extract masing – masing ) menjadi libclntsh.so.old , ini cukup penting karena ketika saya gunakan file libclntsh.so yang asli ini terjadi error
  6. Buat symlink untuk dengan perintah ln -s /data/master/instantclient_19_6/libclntsh.19.1.so  /data/master/instantclient_19_6/libclntsh.so  (sesuaikan sendiri sesuai dengan path hasil extract instantclient kita )
  7. Buat satu file configurasi dalam folder /etc/ld.so.conf.d/oracle-instantclient.conf  dimana file tersebut berisi path dari instantclient kita untuk memberitahukan ld_library posisi dari instantclient kita. Berikut contoh di laptop saya
    /data/master/instantclient_19_6
    
  8. Langkah selanjutkan kita aktifkan extension tersebut, buat file dengan nama 20-oci.ini dalam folder /etc/php/7.4/mods-available dengan isi extension=oci8.so
  9. Agar di cli juga aktif maka kita perlu membuat symlink saja dalam folder /etc/php/7.4/cli/conf.d dengan perintah sudo ln -s /etc/php/7.4/mods-available/20-oci.ini /etc/php/7.4/cli/conf.d/20-oci.ini
  10. Untuk memastikan kita bisa cek melalui perintah php -m jika berhasil maka module oci8 akan ada dalam list extension yang telah terinstall seperti dibawah ini
    [PHP Modules]
    apc
    apcu
    bcmath
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    FFI
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    igbinary
    intl
    json
    libxml
    mbstring
    mysqli
    mysqlnd
    oci8
    odbc
    openssl
    pcntl
    pcre
    PDO
    

Install PDO_OCI

  1. Extract source php yang telah kita download tadi ( langkah 5 diatas ), kemudian melalui command prompt / terminal masuk ke direktori tersebut untuk melakukan compile source dalam folder ext/pdo_oci
  2. Ingat posisi kita berada dalam direktori ext/pdo_oci kemudian ketikkan perintah phpize sehingga kurang lebih akan menghasilkan seperti ini
    ahmad@ahmad-Lenovo-ideapad-300-14ISK:/data/master/php-7.4.6/ext/pdo_oci$ phpize
    Configuring for:
    PHP Api Version: 20190902
    Zend Module Api No: 20190902
    Zend Extension Api No: 320190902
    
  3. Langkah selanjutnya kita lakukan proses configure, masih ingat posisi path instantclient kita kan ? Jika masih ingat kita lanjutkan mengetikkan perintah ./configure –with-pdo-oci=instantclient,/data/master/instantclient_19_6,19.6  dimana /data/master/instantclient_19_6 adalah path saya menyimpan instantclient kemudian 19.6 adalah versi instantclient saya
    ahmad@ahmad-Lenovo-ideapad-300-14ISK:/data/master/php-7.4.6/ext/pdo_oci$ ./configure --with-pdo-oci=instantclient,/data/master/instantclient_19_6,19.6
    checking for grep that handles long lines and -e... /bin/grep
    checking for egrep... /bin/grep -E
    checking for a sed that does not truncate output... /bin/sed
    checking for pkg-config... /usr/bin/pkg-config
    checking pkg-config is at least version 0.9.0... yes
    checking for cc... cc
    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 cc accepts -g... yes
    checking for cc option to accept ISO C89... none needed
    checking how to run the C preprocessor... cc -E
    checking for icc... no
    checking for suncc... no
    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-pc-linux-gnu
    checking host system type... x86_64-pc-linux-gnu
    checking target system type... x86_64-pc-linux-gnu
    checking for PHP prefix... /usr
    checking for PHP includes... -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib
    checking for PHP extension directory... /usr/lib/php/20190902
    checking for PHP installed headers prefix... /usr/include/php/20190902
    checking if debug is enabled... no
    checking if zts is enabled... no
    checking for gawk... gawk
    checking Oracle OCI support for PDO... yes, shared
    checking Oracle Install-Dir... instantclient,/data/master/instantclient_19_6,19.6
    checking if that is sane... yes
    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 size of long... 8
    checking if we're at 64-bit platform... yes
    checking Oracle version... 19.1
    checking for oci.h... /data/master/instantclient_19_6/sdk/include
    checking for OCIEnvCreate in -lclntsh... yes
    checking for OCIEnvNlsCreate in -lclntsh... yes
    checking for OCIStmtFetch2 in -lclntsh... yes
    checking for PDO includes... /usr/include/php/20190902/ext
    checking for a sed that does not truncate output... /bin/sed
    checking for ld used by cc... /usr/bin/ld
    checking if the linker (/usr/bin/ld) is GNU ld... yes
    checking for /usr/bin/ld option to reload object files... -r
    checking for BSD-compatible nm... /usr/bin/nm -B
    checking whether ln -s works... yes
    checking how to recognize dependent libraries... pass_all
    checking dlfcn.h usability... yes
    checking dlfcn.h presence... yes
    checking for dlfcn.h... yes
    checking the maximum length of command line arguments... 1572864
    checking command to parse /usr/bin/nm -B output from cc object... ok
    checking for objdir... .libs
    checking for ar... ar
    checking for ranlib... ranlib
    checking for strip... strip
    checking if cc supports -fno-rtti -fno-exceptions... no
    checking for cc option to produce PIC... -fPIC
    checking if cc PIC flag -fPIC works... yes
    checking if cc static flag -static works... yes
    checking if cc supports -c -o file.o... yes
    checking whether the cc linker (/usr/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
    
    creating libtool
    appending configuration tag "CXX" to libtool
    configure: patching config.h.in
    configure: creating ./config.status
    config.status: creating config.h
    
    
  4. Lalu saatnya kita lakukan instalasi dengan perintah sudo make install kalau tidak ada error tampilannya kurang lebih seperti ini
    ahmad@ahmad-Lenovo-ideapad-300-14ISK:/data/master/php-7.4.6/ext/pdo_oci$ sudo make install
    /bin/bash /data/master/php-7.4.6/ext/pdo_oci/libtool --mode=compile cc -I/usr/include/php/20190902/ext -I. -I/data/master/php-7.4.6/ext/pdo_oci -DPHP_ATOM_INC -I/data/master/php-7.4.6/ext/pdo_oci/include -I/data/master/php-7.4.6/ext/pdo_oci/main -I/data/master/php-7.4.6/ext/pdo_oci -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/data/master/instantclient_19_6/sdk/include -DHAVE_CONFIG_H -g -O2 -c /data/master/php-7.4.6/ext/pdo_oci/pdo_oci.c -o pdo_oci.lo
    mkdir .libs
    cc -I/usr/include/php/20190902/ext -I. -I/data/master/php-7.4.6/ext/pdo_oci -DPHP_ATOM_INC -I/data/master/php-7.4.6/ext/pdo_oci/include -I/data/master/php-7.4.6/ext/pdo_oci/main -I/data/master/php-7.4.6/ext/pdo_oci -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/data/master/instantclient_19_6/sdk/include -DHAVE_CONFIG_H -g -O2 -c /data/master/php-7.4.6/ext/pdo_oci/pdo_oci.c -fPIC -DPIC -o .libs/pdo_oci.o
    /bin/bash /data/master/php-7.4.6/ext/pdo_oci/libtool --mode=compile cc -I/usr/include/php/20190902/ext -I. -I/data/master/php-7.4.6/ext/pdo_oci -DPHP_ATOM_INC -I/data/master/php-7.4.6/ext/pdo_oci/include -I/data/master/php-7.4.6/ext/pdo_oci/main -I/data/master/php-7.4.6/ext/pdo_oci -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/data/master/instantclient_19_6/sdk/include -DHAVE_CONFIG_H -g -O2 -c /data/master/php-7.4.6/ext/pdo_oci/oci_driver.c -o oci_driver.lo
    cc -I/usr/include/php/20190902/ext -I. -I/data/master/php-7.4.6/ext/pdo_oci -DPHP_ATOM_INC -I/data/master/php-7.4.6/ext/pdo_oci/include -I/data/master/php-7.4.6/ext/pdo_oci/main -I/data/master/php-7.4.6/ext/pdo_oci -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/data/master/instantclient_19_6/sdk/include -DHAVE_CONFIG_H -g -O2 -c /data/master/php-7.4.6/ext/pdo_oci/oci_driver.c -fPIC -DPIC -o .libs/oci_driver.o
    /bin/bash /data/master/php-7.4.6/ext/pdo_oci/libtool --mode=compile cc -I/usr/include/php/20190902/ext -I. -I/data/master/php-7.4.6/ext/pdo_oci -DPHP_ATOM_INC -I/data/master/php-7.4.6/ext/pdo_oci/include -I/data/master/php-7.4.6/ext/pdo_oci/main -I/data/master/php-7.4.6/ext/pdo_oci -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/data/master/instantclient_19_6/sdk/include -DHAVE_CONFIG_H -g -O2 -c /data/master/php-7.4.6/ext/pdo_oci/oci_statement.c -o oci_statement.lo
    cc -I/usr/include/php/20190902/ext -I. -I/data/master/php-7.4.6/ext/pdo_oci -DPHP_ATOM_INC -I/data/master/php-7.4.6/ext/pdo_oci/include -I/data/master/php-7.4.6/ext/pdo_oci/main -I/data/master/php-7.4.6/ext/pdo_oci -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/data/master/instantclient_19_6/sdk/include -DHAVE_CONFIG_H -g -O2 -c /data/master/php-7.4.6/ext/pdo_oci/oci_statement.c -fPIC -DPIC -o .libs/oci_statement.o
    /data/master/php-7.4.6/ext/pdo_oci/oci_statement.c:719:2: warning: initialization of ‘ssize_t (*)(php_stream *, char *, size_t)’ {aka ‘long int (*)(struct _php_stream *, char *, long unsigned int)’} from incompatible pointer type ‘size_t (*)(php_stream *, char *, size_t)’ {aka ‘long unsigned int (*)(struct _php_stream *, char *, long unsigned int)’} [-Wincompatible-pointer-types]
    719 | oci_blob_read,
    | ^~~~~~~~~~~~~
    /data/master/php-7.4.6/ext/pdo_oci/oci_statement.c:719:2: note: (near initialization for ‘oci_blob_stream_ops.read’)
    /bin/bash /data/master/php-7.4.6/ext/pdo_oci/libtool --mode=link cc -DPHP_ATOM_INC -I/data/master/php-7.4.6/ext/pdo_oci/include -I/data/master/php-7.4.6/ext/pdo_oci/main -I/data/master/php-7.4.6/ext/pdo_oci -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/data/master/instantclient_19_6/sdk/include -DHAVE_CONFIG_H -g -O2 -o pdo_oci.la -export-dynamic -avoid-version -prefer-pic -module -rpath /data/master/php-7.4.6/ext/pdo_oci/modules pdo_oci.lo oci_driver.lo oci_statement.lo -Wl,-rpath,/data/master/instantclient_19_6 -L/data/master/instantclient_19_6 -lclntsh
    cc -shared .libs/pdo_oci.o .libs/oci_driver.o .libs/oci_statement.o -L/data/master/instantclient_19_6 -lclntsh -Wl,-rpath -Wl,/data/master/instantclient_19_6 -Wl,-soname -Wl,pdo_oci.so -o .libs/pdo_oci.so
    creating pdo_oci.la
    (cd .libs && rm -f pdo_oci.la && ln -s ../pdo_oci.la pdo_oci.la)
    /bin/bash /data/master/php-7.4.6/ext/pdo_oci/libtool --mode=install cp ./pdo_oci.la /data/master/php-7.4.6/ext/pdo_oci/modules
    cp ./.libs/pdo_oci.so /data/master/php-7.4.6/ext/pdo_oci/modules/pdo_oci.so
    cp ./.libs/pdo_oci.lai /data/master/php-7.4.6/ext/pdo_oci/modules/pdo_oci.la
    PATH="$PATH:/sbin" ldconfig -n /data/master/php-7.4.6/ext/pdo_oci/modules
    ----------------------------------------------------------------------
    Libraries have been installed in:
    /data/master/php-7.4.6/ext/pdo_oci/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.
    ----------------------------------------------------------------------
    Installing shared extensions: /usr/lib/php/20190902/
    
    
  5. Langkah selanjutkan kita aktifkan extension tersebut, buat file dengan nama 20-pdo-oci.ini dalam folder /etc/php/7.4/mods-available dengan isi extension=pdo_oci.so
  6. Agar di cli juga aktif maka kita perlu membuat symlink saja dalam folder /etc/php/7.4/cli/conf.d dengan perintah sudo ln -s /etc/php/7.4/mods-available/20-pdo-oci.ini /etc/php/7.4/cli/conf.d/20-pdo-oci.ini
  7. Untuk memastikan kita bisa cek melalui perintah php -m jika berhasil maka module oci8 akan ada dalam list extension yang telah terinstall seperti dibawah ini 
    [PHP Modules]
    apc
    apcu
    bcmath
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    FFI
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    igbinary
    intl
    json
    libxml
    mbstring
    mysqli
    mysqlnd
    oci8
    odbc
    openssl
    pcntl
    pcre
    PDO
    pdo_dblib
    pdo_mysql
    PDO_OCI
    PDO_ODBC
    pdo_pgsql
    pdo_sqlite
    
Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d blogger menyukai ini: