Oracle Instant Client is a free set of easily installed libraries that allow programs to connect to local or remote Oracle Database instances. To use Instant Client an existing database is needed because Instant Client does not include one. Typically the database will be on another machine. If the database is local then Instant Client, although convenient and still usable, is generally not needed because PHP OCI8 can be built using the database libraries.
When using Instant Client 12c, PHP OCI8 connects to all editions of Oracle 10.x, 11.x and 12 databases. Earlier versions of Oracle Instant Client can be used for connecting to older databases. The latest and greatest Oracle functionality is only available when PHP OCI8 2.0 uses Oracle Instant Client 12c to connect to Oracle Database 12c.
On Linux, PHP is often manually compiled because the packaged version is generally not up to date. However, if you don't wish to compile code there are some options:
- PHP 5.5 and PHP OCI8 packages for Oracle Linux are available from oss.oracle.com. Instant Client will need to be installed separately from OTN.
- The OCI8 extension package for the default Oracle Linux PHP version is on the Unbreakable Linux Network. Instant Client is also on ULN.
All of these solutions simplify the installation process for PHP. However, if you want more control, the remainder of this article shows a way to manually install and use PHP with Oracle Database.
Enabling the PHP OCI8 Extension on Linux
The following steps show how to build PHP and OCI8 from source code.Install Apache
- Install the Apache HTTP Server and development packages, for example with:
# yum install httpd httpd-devel
Install PHP
- Download the PHP 5.5 source code.
- Install PHP following Installation on Unix systems in the PHP manual.
For example:
# tar -jxf php-5.5.10.tar.bz2 # cd php-5.5.10 # ./configure --with-apxs2=/usr/sbin/apxs --with-zlib . . . # make install
At this stage, don't configure the OCI8 extension.
The Zlib extension is needed for thepecl
command used below.
Install Instant Client
- Download the Basic and the SDK instant client packages from the OTN Instant Client page. Either the ZIP files or RPMs can be used.
- Install the RPMs as the root user, for example: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
# rpm -Uvh oracle-instantclient12.1-basic-12.1.0.1.0-1.x86_64.rpm # rpm -Uvh oracle-instantclient12.1-devel-12.1.0.1.0-1.x86_64.rpm
The first RPM puts Oracle libraries in/usr/lib/oracle/12.1/client64/lib
and the second creates headers in/usr/include/oracle/12.1/client64
.
If you are using the ZIP files, the SDK should unzipped to the same directory as the basic package, and a symbolic link manually created:
# unzip instantclient-basic-linux.x64-12.1.0.1.0.zip # unzip instantclient-sdk-linux.x64-12.1.0.1.0.zip # cd instantclient_12_1 # ln -s libclntsh.so.12.1 libclntsh.so
- Install your Linux distribution's
libaio
orlibaio1
package, if it is not already present.
Install PHP OCI8
- The PHP OCI8 extension from PECL
is always the current version. PECL OCI8 2.0 has more features
than the OCI8 1.4 included in PHP 5.5's source bundle. It will
compile with PHP 5.2 onward. The latest production extension can
be automatically downloaded and added to PHP using:
# pecl install oci8
this gives:
downloading oci8-2.0.8.tgz ... Starting to download oci8-2.0.8.tgz (190,854 bytes) .................done: 190,854 bytes 11 source files, building running: phpize Configuring for: PHP Api Version: 20121113 Zend Module Api No: 20121212 Zend Extension Api No: 220121212 Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :
If you have the Instant Client RPMs, hitEnter
and PECL will automatically build and install anoci8.so
shared library. If you have the Instant Client ZIP files, or want a specific version of Instant Client used, then explicitly give the appropriate path after "instantclient,
":
instantclient,/usr/lib/oracle/12.1/client64/lib
Use an explicit, absolute path sincepecl
does not expand environment variables.
If you don't have thepecl
program, you can alternatively download the OCI8 package in a browser and then install it with:
# tar -xzf oci8-2.0.8.tgz # cd oci8-2.0.8 # phpize # ./configure --with-oci8=instantclient,/usr/lib/oracle/12.1/client64/lib # make install
- Enable the PHP OCI8 extension by editing
/etc/php.ini
and adding:
extension=oci8.so
Also confirmextension_dir
points to the directory theoci8.so
file was copied into during the build. - Ensure Instant Client libraries are found by adding the Instant Client directory to
/etc/ld.so.conf
, or manually setLD_LIBRARY_PATH
to/usr/lib/oracle/12.1/client64/lib
. You might also want to set standard Oracle environment variables such asTNS_ADMIN
andNLS_LANG
. IfNLS_LANG
is not set, a default local environment will be assumed.
It is important to set all Oracle environment variables before starting Apache so that the OCI8 process environment is correctly initialized. Setting environment variables in PHP scripts can lead to obvious or non-obvious problems. On Oracle Linux, export environment variables in/etc/sysconfig/httpd
, for example:
export ld_library_path=/usr/lib/oracle/12.1/client64/lib
On Debian-based machines set the variables in/etc/apache2/envvars
.
Restart Apache
- Complete the installation by restarting Apache, for example with:
# service httpd restart
Không có nhận xét nào:
Đăng nhận xét