在centos 7.3中为xampp x64 7.1.1中安装oci8.so及oracle客户端

导语:有一台操作系统为centos 7.3的64位服务器,需要通过web访问远程的oracle数据库服务器,XAMPP版本为x64的7.1.1。它需要先安装oracle的客户端,然后再为php安装oci8。以下是详细的安装配置过程。

安装oracle客户端

下载oracle客户端

注意,现在oracle的官网下载软件需要注册,请先注册一个账号后再下载。oracle客户端的下载地址如下:

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

叶子下载的是rpm版本,上传到服务器后使用rpm方式安装,另外,如果你不需要在当前服务器上操作数据库,那么sqlplus可以不安装。

oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm

安装oracle库和客户端

[root@ywzc ~]# rpm -ivh  oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:oracle-instantclient12.2-basic-12################################# [100%]


[root@ywzc ~]# rpm -ivh  oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:oracle-instantclient12.2-devel-12################################# [100%]
   
[root@ywzc ~]# rpm -ivh oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:oracle-instantclient12.2-sqlplus-################################# [100%]

加载oracle动态库

安装完成后,需要加载oracle动态库。动态库文件的搜索路径除了通过 LD_LIBRARY_PATH 来指明,还可以在 /etc/ld.so.conf 文件中添加库的搜索路径。

vi /etc/ld.so.conf
   
/usr/lib/oracle/12.2/client64/lib

刷新oracle动态库

ldconfig

安装oci8

下载oci8

下载oci8-2.1.4.tgz,叶子下载的是源码包,需要编译安装。因为叶子使用的是php7,所以下载了2.1.4版本,其他版本的php请下载低版本的oci8。

下载地址:http://pecl.php.net/package/oci8

上传到服务器的/usr/local/src目录。叶子一般放在这个目录,如果您需要放在其他的目录,也是可以的。

切换目录

cd /usr/local/src

解压压缩包文件

tar -xvzf oci8-2.1.4.tgz

切换目录到oci8-2.1.4

cd oci8-2.1.4

用phpize生成configure配置文件,如果不知道phpize在哪里,请用find命令查找。

find / -name phpize

在oci8-2.1.4这个目录下执行命令

/opt/lampp/bin/phpize

下面是服务器上的执行过程。

[root@ywzc src]# cd oci8-2.1.4
[root@ywzc oci8-2.1.4]# ls
config.m4   CREDITS  oci8.c             oci8_dtrace.d     oci8_lob.c        php_oci8.h      README
config.w32  LICENSE  oci8_collection.c  oci8_interface.c  oci8_statement.c  php_oci8_int.h  tests
[root@ywzc oci8-2.1.4]# find / -name phpize
/opt/lampp/bin/phpize
[root@ywzc oci8-2.1.4]# /opt/lampp/bin/phpize
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
[root@ywzc oci8-2.1.4]# ls
acinclude.m4    config.guess  configure     install-sh       missing            oci8_dtrace.d     php_oci8.h      tests
aclocal.m4      config.h.in   configure.in  LICENSE          mkinstalldirs      oci8_interface.c  php_oci8_int.h
autom4te.cache  config.m4     config.w32    ltmain.sh        oci8.c             oci8_lob.c        README
build           config.sub    CREDITS       Makefile.global  oci8_collection.c  oci8_statement.c  run-tests.php

执行configure

configure是用来检测你的安装平台的目标特征的。

./configure --with-php-config=/opt/lampp/bin/php-config --with-oci8=shared,instantclient,/usr/lib/oracle/12.2/client64/lib


checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
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 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: creating ./config.status
config.status: creating config.h

编译安装

make && make install


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:     /opt/lampp/lib/php/extensions/no-debug-non-zts-20160303/

开启数据库服务器的防火墙

添加防火墙规则

这台数据库服务器使用的操作系统是CENTOS7.3,防火墙是firewall,进入它的配置文件public.xml,添加以下代码。

vi /etc/firewalld/zones/public.xml 

……
 <rule family="ipv4">
 <source address="134.166.0.111"/>
 <port protocol="tcp" port="1521"/>
 <accept/>
 </rule>
……  

重启防火墙

firewall-cmd --reload 

在php中开启oci8.so

打开php.ini,在php.ini中设置以下代码。如果不知道php.ini在什么地方,请使用find / -name php.ini来搜索。

vi php.ini

……

extension=oci8.so

……

重启web服务

/opt/lampp/lampp restart

结束

你学会了吗?

发表评论

邮箱地址不会被公开。 必填项已用*标注