Linux下PHP开启Oracle支持(oci8)
使用php的常见问题是:编译php时忘记添加某扩展,后来想添加扩展,但是因为安装php后又装了一些东西如PEAR等,不想删除目录重装,那么此时就需要自己重新增加某模块支持了, Linux操作系统下可以用phpize给PHP动态添加扩展. 下面就以扩展模块 oci8为例(php连
使用php的常见问题是:编译php时忘记添加某扩展,后来想添加扩展,但是因为安装php后又装了一些东西如PEAR等,不想删除目录重装,那么此时就需要自己重新增加某模块支持了,Linux操作系统下可以用phpize给PHP动态添加扩展.下面就以扩展模块 oci8为例(php连接oracle数据库需要改扩展支持)做简单的说明.(以下所有资源可以访问http://download.csdn.net/detail/haiqiao_2010/8294513 进行统一下载)
1.下载Oracle客户端程序包,其中包含OCI、OCCI和JDBC-OCI等相关文件
1.1 根据Linux系统选择对应的软件,我的为32位系统,所以下载如下文件:oracle-instantclient11.2-basic-11.2.0.3.0-1.i386.rpm
oracle-instantclient11.2-devel-11.2.0.3.0-1.i386.rpm
1.2下载地址: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html (Oracle官网下载需要注册用户)
2.安装oracle客户端,运行以下命令即可:
rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0.i386.rpm
rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0.i386.rpm
3.安装oci8 php扩展
3.1 下载oci8-1.4.10.tgz
下载地址:http://pecl.php.net/get/oci8-1.4.10.tgz
3.2 把下载文件上传至linux服务器,并进行解压
命令:tar zxvf oci8-1.4.10.tgz#解压
3.3 转到解压目录
命令:cd oci8-1.4.10
3.4 使用phpize准备 PHP 外挂模块的编译环境,会根据指定的环境变量生成编译时需要的makefile,phpize是属于php-devel的内容,所以centos下只要运行yum install php-devel进行安装即可 (注意:/usr/local/php/bin/phpize 为我的php目录,不同则需改之;如果是64位的系统,client改成client64)
/usr/local/php/bin/phpize CFLAGS="-I/usr/lib/oracle/11.1/client" CXXFLAGS="-I/usr/lib/oracle/11.1/client"
3.5 编译,安装
要有与现有php完全相同的php压缩包。我用的是php-5.5.3.tar.gz。展开后进入里面的ext/oci8目录下,
然后执行命令: /usr/local/php/bin/phpize #这是一个可执行的文本文件,要确保它在系统中
会发现当前目录下多了一些configure文件,
如果没报错,则运行命令;
./configure --with-php-config=/usr/local/php/bin/php-config --with-oci8=/usr/lib/oracle/11.1/client
注意要先确保/usr/local/php/bin/php-config存在。如果你的php安装路径不是默认的,要改。
再运行以下命令 ,然后它告诉你一个目录,你把该目录下的oci8.so拷贝到你php.ini中的extension_dir指向的目录中
make install
需要强调的是make的时候会报错,显示各种找不到库文件,需要对makefile文件进行修改加入oralce的运行库地址
打开makefile,寻找INCLUDE,形式如下:
INCLUDES = -I/usr/local/php/include/php -I/usr/include/oracle/10.2.0.3/client
然后在末尾加上="-I/usr/lib/oracle/11.1/client,然后重新make就会成功了。
4. 修改PHP.ini(/usr/local/php/etc/php.ini)
在extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"后增加一行:
extension = "oci8.so"
注意:要确保/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ 该目录下有oci8.so文件
5.重启apache,让oci生效
6.在web目录下创建phpinfo.php文件在其中输入一下内容,并通过web访问
<?php phpinfo(); ?>
如果找到OCI8的部分就说明OCI安装正常了,如下图所示

说明oci8安装成功,接下来就可以使用php访问oracle数据库了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.
