Cài Đặt Oracle instant Client và PHP Oci8

39 Likes Comment

Oci8 là phần kết nối php với oracle để dùng oracle database như mysql.

Đầu tiên bạn phải cài php đã giờ mình đang dùng php 7.4, và sẽ cài Oci8 trên này. chúng ta sẽ tiến hành cài thông qua lệnh: (để chạy được lệnh pecl thì các bạn phải cài php-pear vào nhé)

pecl install oci8-2.2.0

Tuy nhiên kết quả chúng tâ nhận được sẽ là lỗi như dưới dây nguyên nhân là chưa có phpize để kết nối.

Tiến hành cài phpize

yum install php-devel

sau đó chạy lại lệnh cài thông qua pecl thì giờ thì là lỗi oracle instanl client chưa có.

Chúng ta đi cài nó nào. đầu tiên chúng ta cần tải phần mềm về

wget https://download.oracle.com/otn_software/linux/instantclient/19600/oracle-instantclient19.6-basic-19.6.0.0.0-1.x86_64.rpm
 
wget https://download.oracle.com/otn_software/linux/instantclient/19600/oracle-instantclient19.6-devel-19.6.0.0.0-1.x86_64.rpm

Sau khi tải về thì dùng rpm để cài

rpm -ivh oracle-instantclient19.6-basic-19.6.0.0.0-1.x86_64.rpm
 
rpm -ivh oracle-instantclient19.6-devel-19.6.0.0.0-1.x86_64.rpm

ở đây mình dùng bản cũ này do thói quen các bạn có thể lấy bản mới và cài tương tự link tải ở đây

Thêm đoạn cấu hình sau vào file ~/bashrc bạn dùng vi/vim/nano gì đó sửa là được

export ORACLE_HOME=/usr/lib/oracle/19.6/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

nếu khi cài gặp lỗi

error: Failed dependencies:
        libaio is needed by oracle-instantclient-basic-21.1.0.0.0-1.x86_64

Chúng ta xử lý bằng cách chạy các lệnh sau

yum localinstall oracle* --nogpgcheck

sau khi song chúng ta sử file ~/.bashrc thêm 2 dòng bên dưới

export ORACLE_HOME=/usr/lib/oracle/19.6/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

Sau đó chạy lại pecl xem sao nhưng nó lại báo một lỗi liên quan tới make

Chúng ta xử lý nó như sau dùng lệnh sau tải mã nguồn về

pecl download oci8-2.2.0

Sau đó giải nén

tar -zxf oci8-2.2.0.tgz
cd oci8-2.2.0

chạy lện sau

phpize
export PHP_DTRACE=yes
./configure -with-oci8=shared,$ORACLE_HOME

sau khi chạy song chúng ta tìm file còn thiếu thông qua lệnh

find /usr/include/oracle -name oci.h

của mình ở đây là:

/usr/include/oracle/19.6/client64/oci.h

thì mình sẽ mở Makefile thêm dòng sau INSTALL_DATA

EXTRA_INCLUDES = -I/usr/include/oracle/19.6/client64

sau đó chạy lệnh

make install

Như vậy là song, trong trường hợp gặp lỗi như sau

/root/oci8-2.2.0/php_oci8_int.h:46:29: fatal error: oci8_dtrace_gen.h: No such file or directory
 #include "oci8_dtrace_gen.h"

chạy lệnh sau và sau đó chạy lại lệnh make install

yum install systemtap-sdt-devel

sau đó bạn cấu hình php như bình thường bằng cách thêm file oci8.ini như sau vào thư mục /etc/php.d với nội dung như sau:

; Enable oci8 extension module
extension=oci8

; Connection: Enables privileged connections using external
; credentials (OCI_SYSOPER, OCI_SYSDBA)
; http://php.net/oci8.privileged-connect
;oci8.privileged_connect = Off

; Connection: The maximum number of persistent OCI8 connections per
; process. Using -1 means no limit.
; http://php.net/oci8.max-persistent
;oci8.max_persistent = -1

; Connection: The maximum number of seconds a process is allowed to
; maintain an idle persistent connection. Using -1 means idle
; persistent connections will be maintained forever.
; http://php.net/oci8.persistent-timeout
;oci8.persistent_timeout = -1

; Connection: The number of seconds that must pass before issuing a
; ping during oci_pconnect() to check the connection validity. When
; set to 0, each oci_pconnect() will cause a ping. Using -1 disables
; pings completely.
; http://php.net/oci8.ping-interval
;oci8.ping_interval = 60

; Connection: Set this to a user chosen connection class to be used
; for all pooled server requests with Oracle 11g Database Resident
; Connection Pooling (DRCP).  To use DRCP, this value should be set to
; the same string for all web servers running the same application,
; the database pool must be configured, and the connection string must
; specify to use a pooled server.
;oci8.connection_class =

; High Availability: Using On lets PHP receive Fast Application
; Notification (FAN) events generated when a database node fails. The
; database must also be configured to post FAN events.
;oci8.events = Off

; Tuning: This option enables statement caching, and specifies how
; many statements to cache. Using 0 disables statement caching.
; http://php.net/oci8.statement-cache-size
;oci8.statement_cache_size = 20

; Tuning: Enables statement prefetching and sets the default number of
; rows that will be fetched automatically after statement execution.
; http://php.net/oci8.default-prefetch
;oci8.default_prefetch = 100

; Compatibility. Using On means oci_close() will not close
; oci_connect() and oci_new_connect() connections.
; http://php.net/oci8.old-oci-close-semantics
;oci8.old_oci_close_semantics = Off

check php và song

0 0 votes
Article Rating

You might like

Avatar

About the Author: Vô Ưu

Xin chào! Tôi là Vouu, người sáng lập blog này. Tôi là một người yêu thích. Tôi có một công việc ban ngày với tư cách là một chuyên viên bơm vá săm xe các loại, và trang web này là một trong những hoạt động yêu thích của tôi, đặc biệt là trong những lúc rảnh rỗi. Hy vọng bạn thích sử dụng trang web này, và nó sẽ mang lại cho bạn nhiều điều bổ ích. Phản hồi từ người đọc sẽ truyền cảm hứng cho tôi để tôi có thể viết được nhiều hơn nữa !. Bạn chỉ cần để lại nhận xét bên dưới nếu bạn thấy bài viết này hữu ích. Chúc bạn ngày mới tốt lành!
Subscribe
Notify of
guest
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x