Home  >  Article  >  Backend Development  >  Install oracle client and configure php5.3 under Linux, oraclephp5.3_PHP tutorial

Install oracle client and configure php5.3 under Linux, oraclephp5.3_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:17:32872browse

Install oracle client under Linux and configure php5.3, oraclephp5.3

Since the project requires the Oracle client compilation of php5.3 under Linux, I would like to briefly introduce the steps and detours taken.

1. Download the Oracle client package, which contains related files such as OCI, OCCI and JDBC-OCI.

1.1 Download file address

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Select the corresponding software according to the version of the operating system. What I need is X86_64 selection
Instant Client for Linux x86-64

The files that need to be downloaded for 1.2 are as follows:

Copy code The code is as follows:

oracle-instantclient11.1-basic-11.1.0.7.0-1.x86_64.rpm
oracle-instantclient11.1-devel-11.1.0.7.0-1.x86_64.rpm
oracle-instantclient11.1-sqlplus-11.1.0.7.0-1.x86_64.rpm

One thing that needs to be emphasized is that you need to register an oracle account to download normally.

2. Install the Oracle client package.

Upload the program package to the specified directory on the server

Copy code The code is as follows:

chmod +x *.rpm
#Give execution permissions to the RPM package
rpm -ivh oracle-instantclient11.1-basic-11.1.0.7.0-1.x86_64.rpm oracle-instantclient11.1-devel-11.1.0.7.0-1.x86_64.rpm oracle-instantclient11.1-sqlplus-11.1 .0.7.0-1.x86_64.rpm
#Install RPM package
echo "/usr/lib/oracle/11.1/client64/lib/" > /etc/ld.so.conf.d/oracle_client.conf
#Add the library path to the default load
/sbin/ldconfig
#Reload dynamic link library

3. Install the OCI8 php extension (the installation path of php specified here is /usr/local/webserver/php)

Copy code The code is as follows:

yum install libaio
#yum installs the libaio library. libaio is an asynchronous non-blocking interface under Linux. It provides a way to read and write files in an asynchronous non-blocking way, and the reading and writing efficiency is relatively high
wget http://pecl.php.net/get/oci8-1.4.10.tgz
#DownloadOCIExtension
tar zxvf oci8-1.4.10.tgz
#unzip
cd oci8-1.4.10
/usr/local/webserver/php/bin/phpize CFLAGS="-I/usr/lib/oracle/11.1/client64" CXXFLAGS="-I/usr/lib/oracle/11.1/client64"
#Use phpize to prepare the compilation environment of the PHP plug-in module. The makefile required for compilation will be generated according to the specified environment variables. phpize is the content of php-devel, so under centos, just run yum install php-devel to install it
./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-oci8=/usr/lib/oracle/11.1/client64
make
make install
#Compile, install

It should be emphasized that when making, an error will be reported, showing that various library files cannot be found. The makefile needs to be modified to add the runtime address of oralce
Open the makefile and look for INCLUDE in the following form:
INCLUDES = -I/usr/local/php/include/php -I/usr/include/oracle/10.2.0.3/client
Then add =="-I/usr/lib/oracle/11.1/client64 at the end, and then make again and it will succeed.

4. Modify PHP.ini (/usr/local/webserver/php/etc/php.ini)

Add a line after extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/":

Copy code The code is as follows:

extension = "oci8.so"

5. Restart apache to allow OCI to take effect

6. Create the phpinfo.php file in the web directory, enter the content in it, and access it through the web

Copy code The code is as follows:

phpinfo();
?>

If you find the OCI8 part, it means that the OCI installation is normal, as shown in the picture below

Next, you can access the Oracle database through PHP. What you need to pay attention to is the Oracle connection string under PHP

Copy code The code is as follows:

$username='***';
$passwd='***';
$protocol='TCP';
$SERVICE_NAME='***';
$ORACLE_SERVER_IP_ADDRESS='***.***.***.***';
$Port='1521′;
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = $protocol)(HOST = $ORACLE_SERVER_IP_ADDRESS)(PORT = $Port)))(CONNECT_DATA=(SID=$SERVICE_NAME)))";
$conn = oci_connect($username,$passwd, $db);
PutEnv("NLS_LANG=SIMPLIFIED CHINESE_CHINA.AL32UTF8");
if (!$conn) {
$e = oci_error();
Print htmlentities($e['message']);
exit;
}else {
echo "Connection to oracle successful!";
Return $conn;
}
?>

How to install Oracle client under linux

Install rpm as root user -ivh oracle-instantclient-basic-11.1.0.1-1.x86_64.rpmrpm -ivh oracle-instantclient-sqlplus-11.1.0.1-1.x86_64.rpm configure vim /etc/profile add export ORACLE_HOME=/usr/lib/oracle/11.1.0.1/client64export ORACLE_BASE=/usr/lib/oracle/11.1.0.1export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATHexport NLS_LANG=AMERICAN_AMERICA.AL32UTF8 After setting the environment variables, you need to restart the machine! Create the configuration file. Create the following directory network/admin in the ORACLE_HOME directory, and create the file tnsnames.ora with the following content: vim /usr/lib/oracle/11.1.0.1/client64/network/admin/tnsnames.ora# tnsnames.ora Network Configuration File: /opt/oracle10g/u01/network/admin/tnsnames.ora# Generated by Oracle configuration tools.111 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.15.111)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = dmsdb) ) ) Test to the ORACLE_HOME/bin directory and execute the command: [yleesun@centos bin]$ ./sqlplus zxd/zxd@111Copyright (c) 1982, 2011, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL>Test successful! Note: If the following error occurs: sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory, the environment variable does not take effect!

How to install Oracle client under linux

Install as root user
rpm -ivh oracle-instantclient-basic-11.1.0.1-1.x86_64.rpm
rpm -ivh oracle-instantclient-sqlplus-11.1.0.1-1.x86_64.rpm configuration
vim /etc/profile add
export ORACLE_HOME=/usr/lib/oracle/11.1.0.1/client64
export ORACLE_BASE=/usr/lib/oracle/11.1.0.1
export LD_LIBRARY_PATH=$ ORACLE_HOME/lib:$LD_LIBRARY_PATH
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
After setting the environment variables, you need to restart the machine!
Create configuration file
Create the following directory network/admin in the ORACLE_HOME directory, and create the file tnsnames.ora with the following content:
vim /usr/lib/oracle/11.1.0.1/client64/network/admin /tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle10g/u01/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.111 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.15.111)(PORT = 1521)))
(CONNECT_DATA =
(SERVICE_NAME = dmsdb))) TEST
to ORACLE_HOME /bin directory, execute the command:
[yleesun@centos bin]$ ./sqlplus zxd/zxd@111
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL test successful! Note:
If the following error occurs:
It means the environment variable does not take effect!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/892259.htmlTechArticleInstall the oracle client under Linux and configure php5.3, oraclephp5.3 because the project requires php5 under Linux. 3 oracle client compilation, briefly introduce the steps and detours taken. 1. Download O...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn