Today : 36
Yesterday : 63
Total : 364,412
관리 메뉴
프로필사진 글목록 방명록 이웃추가
Today:36     Yesterday:63     Total:364,412

JunToday.com

Rocky Linux 8.5에 oracle instant client 설치, php7 + oci8 연동 본문

생활속의 IT 노하우/리눅스

Rocky Linux 8.5에 oracle instant client 설치, php7 + oci8 연동

JunToday 2022. 8. 19. 11:04
[root@localhost ~]# dnf -y install httpd php php-devel wget make libnsl

설치 완료되면

[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl enable php-fpm

서비스 enable 시켜주고

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget https://download.oracle.com/otn_software/linux/instantclient/217000/oracle-instantclient-basic-21.7.0.0.0-1.el8.x86_64.rpm
[root@localhost src]# wget https://download.oracle.com/otn_software/linux/instantclient/217000/oracle-instantclient-sqlplus-21.7.0.0.0-1.el8.x86_64.rpm
[root@localhost src]# wget https://download.oracle.com/otn_software/linux/instantclient/217000/oracle-instantclient-devel-21.7.0.0.0-1.el8.x86_64.rpm
[root@localhost src]# wget http://pecl.php.net/get/oci8-2.2.0.tgz

wget으로 설치파일 다운로드 (사이트에서 직접 다운로드 받아서 sftp나 ftp로 올려도 됨.)

https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html

 

Instant Client for Linux x86-64 (64-bit)

Instant Client Installation for Linux x86-64 (64-bit) For general Instant Client information, see the Home Page. ODBC users should follow the ODBC Installation Instructions. The "Database Client Installation Guide for Linux" chapter on Installing Oracle In

www.oracle.com

http://pecl.php.net/package/oci8

 

PECL :: Package :: oci8

Description The OCI8 extension lets you access Oracle Database. Use 'pecl install oci8' to install for PHP 8.1. Use 'pecl install oci8-3.0.1' to install for PHP 8.0. Use 'pecl install oci8-2.2.0' to install for PHP 7. Use 'pecl install oci8-2.0.12' to inst

pecl.php.net

[root@localhost src]# dnf -y install oracle-instantclient-basic-21.7.0.0.0-1.el8.x86_64.rpm
[root@localhost src]# dnf -y install oracle-instantclient-sqlplus-21.7.0.0.0-1.el8.x86_64.rpm
[root@localhost src]# dnf -y install oracle-instantclient-devel-21.7.0.0.0-1.el8.x86_64.rpm

oracle-instantclient 설치 (제대로 설치되는지 보려고 하나씩 설치함..)

[root@localhost src]# vi /etc/profile.d/oracle.sh
export ORACLE_HOME=/usr/lib/oracle/21/client64/
export TNS_ADMIN=/usr/lib/oracle/21/client64/bin/

환경변수에 oracle.sh 파일 생성하여 내용 추가.

[root@localhost src]# vi /root/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin  <<<<======수정  PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

export PATH

수정.

[root@localhost src]# sqlplus

SQL*Plus: Release 21.7.0.0.0 Production on Thu Aug 18 21:31:04 2022

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Enter user-name:

sqlplus 작동 확인.

여기까지 oracle isntantclient 설치 완료.

다음은 php에 oci8연동

[root@localhost src]# php -r "oci_connect();"
PHP Fatal error:  Uncaught Error: Call to undefined function oci_connect() in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1

요렇게 나오면 연동 안된 상태임.

[root@localhost src]# tar xzvf oci8-2.2.0.tgz

위에서 받은 oci8-2.2.0.tgz 파일 압축 해제(php7버전은 2.2.0버전이라고 함.)

[root@localhost src]# cd oci8-2.2.0
[root@localhost oci8-2.2.0]# phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718

phpize로 확장모듈 컴파일..

[root@localhost oci8-2.2.0]# ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/21/client64/lib/

콘피그

[root@localhost oci8-2.2.0]# ln -s /usr/include/oracle/21/client64/ /usr/lib/oracle/21/client64/lib/include

인클루드 링크 걸어줌..

[root@localhost oci8-2.2.0]# make all install
......
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/src/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.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib64/php/modules/

make all install로 설치.. 에러 안나는지 확인할 것!

[root@localhost oci8-2.2.0]# ll /usr/lib64/php/modules/oci8.so
-rwxr-xr-x 1 root root 897856  8월 18 13:16 /usr/lib64/php/modules/oci8.so

확인!

[root@localhost oci8-2.2.0]# echo 'extension=oci8.so' > /etc/php.d/oci8.ini

php.ini에 extension=oci8.so이 없으면 oci8.ini 파일 생성

[root@localhost oci8-2.2.0]# php -r "oci_connect();"
PHP Warning:  oci_connect() expects at least 2 parameters, 0 given in Command line code on line 1

이렇게 나오면 연동 성공


오라클 클라이언트 버전이 높을 경우 구버전 오라클에 접속되지 않음...

오라클클라이언트 버전 21.7.0.0.0을 설치했더니 오라클10g에 접속이 안됨..

11.2.0.4버전으로 다시 설치..

[root@localhost ~]# cd /usr/lib/oracle/21/client64/lib/
[root@localhost lib]# rm -rf include

include 링크 삭제..

[root@localhost lib]# dnf remove oracle-instantclient-basic-21.7.0.0.0-1.el8.x86_64

설치한 오라클 클라이언트 21.7.0.0.0버전 삭제(이거 삭제하면 나머지도 삭제됨.)

[root@localhost lib]# cd /usr/lib64/php/modules/
[root@localhost modules]# rm -rf oci8.so

php모듈 디렉토리에 생성된 oci8.so 파일 삭제..

oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

오라클 다운로드 페이지에서 다운로드 받은 위 세 파일을 sftp나 ftp로 /usr/local/src에 업로드 (wget으로 받았더니 설치가 안되더라..)

[root@localhost src]# dnf -y install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
[root@localhost src]# dnf -y install oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
[root@localhost src]# dnf -y install oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

11.2설치.

[root@localhost src]# vi /etc/profile.d//oracle.sh
export ORACLE_HOME=/usr/lib/oracle/21/client64/
export TNS_ADMIN=/usr/lib/oracle/21/client64/bin/

이렇게 되어 있던걸

export ORACLE_HOME=/usr/lib/oracle/11.2/client64/
export TNS_ADMIN=/usr/lib/oracle/11.2/client64/bin/
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib/

이렇게 수정.. LD_LIBRARY_PATH 부분 안하면 sqlplus 실행할 때 모듈 없다고 에러나더라..

[root@localhost src]# sqlplus

SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 18 21:58:31 2022

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Enter user-name:

sqlplus 잘 작동함.

[root@localhost src]# rm -rf oci8-2.2.0

재컴파일 해야 하니까 깔끔하게 압축 풀어놨던 oci8-2.2.0 삭제

[root@localhost src]# tar xzvf oci8-2.2.0.tgz

다시 압축 해제.

[root@localhost src]# cd oci8-2.2.0
[root@localhost oci8-2.2.0]# phpize

동일하게 진행.

[root@localhost oci8-2.2.0]# ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib/
[root@localhost oci8-2.2.0]# ln -s /usr/include/oracle/11.2/client64/ /usr/lib/oracle/11.2/client64/lib/include
[root@localhost oci8-2.2.0]# make all install
[root@localhost oci8-2.2.0]# ll /usr/lib64/php/modules/oci8.so

경로만 바꿔서 동일하게 진행.

[root@localhost oci8-2.2.0]# php -r "oci_connect();"
PHP Warning:  oci_connect() expects at least 2 parameters, 0 given in Command line code on line 1

끝.

0 Comments
댓글쓰기 폼