Oracle Support for PHP in Linux (oci8)
A common problem with using php is: I forgot to add an extension when compiling php. I want to add an extension later. But I didn't want to delete the Directory and reinstall it because I installed something like PEAR after installing php, in this case, you need to add a new module. in Linux, you can use phpize to dynamically add extensions to PHP. the following uses the extension module oci8 as an example (php needs to be changed to support expansion when connecting to the oracle database. (all of the following resources are accessible to the http://download.csdn.net/detail/haiqiao_2010/8294513 for unified download)
1. Download the Oracle client package, which contains OCI, OCCI, JDBC-OCI and Other Related Files 1.1 According to the Linux system to select the corresponding software, I am a 32-bit system, so download the following file:
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 official download needs to register users)
2. Install the oracle client and run the following command:
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. Install oci8 php Extension
3.1 download oci8-1.4.10.tgz
: Http://pecl.php.net/get/oci8-1.4.10.tgz
3.2 upload the downloaded file to the linux server and decompress it.
Command: tar zxvf oci8-1.4.10.tgz # Extract
3.3 go to the decompressed directory
Command: cd oci8-1.4.10
3.4 use phpize to prepare the compiling environment of the PHP plug-in module. makefile is generated based on the specified environment variables. phpize is the content of php-devel, therefore, in centos, you only need to run yum install php-devel to install it. (Note:/usr/local/php/bin/phpize is my php Directory. If it is different, you need to change it; for a 64-bit system, change the client to client64)
/Usr/local/php/bin/phpize CFLAGS = "-I/usr/lib/oracle/11.1/client" CXXFLAGS = "-I/usr/lib/oracle/11.1/ client"
3.5 compile and install
There must be a php compressed package identical to the existing php. I use php-5.5.3.tar.gz. Expand and enter the ext/oci8 directory,
Then run the command:/usr/local/php/bin/phpize # This is an executable text file. Make sure it is in the system
Some configure files are added to the current directory,
If no error is reported, run the command;
./Configure -- with-php-config =/usr/local/php/bin/php-config -- with-oci8 =/usr/lib/oracle/11.1/client
Make sure that/usr/local/php/bin/php-config exists. If your php installation path is not the default one, change it.
Run the following command, and then it tells you a directory where you copy the oci8.so file to the directory pointed to by extension_dir in your php. ini file.
Make
Make install
It should be emphasized that an error will be reported during make, indicating that the library files cannot be found. You need to modify the makefile file and add it to the oralce Runtime Library address.
Open makefile and find INCLUDE in the following format:
Using DES =-I/usr/local/php/include/php-I/usr/include/oracle/10.2.0.3/client
Add = "-I/usr/lib/oracle/11.1/client at the end, and then make again.
4. Modify PHP. ini (/usr/local/php/etc/php. ini)
Add a line after extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613:
Extension = "oci8.so"
Note: Make sure the/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/directory contains the oci8.so File
5. Restart apache to make oci take effect. 6. Create the phpinfo. php file in the web directory and enter the content in it.
<?phpphpinfo();?>
If the OCI8 part is found, the OCI installation is normal, as shown in
It indicates that oci8 is successfully installed. Then you can use php to access the oracle database.