Installing PHP and The Oracle Instant Client For Linux and Windows - Updated For DB 12c
Installing PHP and The Oracle Instant Client For Linux and Windows - Updated For DB 12c
Application Development Installing PHP and the Oracle Instant Client for Linux and Windows
Framework For PHP 5.5, OCI8 2.0 and Oracle Database 12c Release 1
Business Intelligence See the version for PHP 5.4 and Oracle Database 11g Release 2
Cloud Computing The easiest way to configure PHP to access a remote Oracle Database is to use the free Oracle Instant Client libraries. This note describes how to
Communications install PHP's OCI8 extension and Oracle Instant Client on Linux and Windows. The Underground PHP and Oracle Manual explains other
installation options and contains more detail.
Database Performance &
Availability PHP OCI8 is the PHP extension for connecting PHP to Oracle Database. OCI8 is open source and included with PHP. The name is derived from
Oracle's C "call interface" API first introduced in version 8 of Oracle Database. PHP OCI8 links with Oracle C client libraries, which are included in
Data Warehousing the Oracle Database software and also in Oracle Instant Client.
Database 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
.NET 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
Dynamic Scripting Languages database libraries.
Embedded 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
Digital Experience
Instant Client 12c to connect to Oracle Database 12c.
Enterprise Architecture
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
Enterprise Management there are some options:
Identity & Security 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.
Java The OCI8 extension package for the default Oracle Linux PHP version is on the Unbreakable Linux Network. Instant Client is also on ULN.
Linux The Zend Server is the recommended PHP distribution. It comes in free and supported versions for Linux and Windows, and includes OCI8 and
Mobile Instant Client.
Service-Oriented Architecture 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.
Solaris
Software Requirements:
SQL & PL/SQL
Software Notes
Systems - All Articles Oracle Instant Download the "Basic" package. On Linux, also download the "SDK" or "devel" package. If space is at a premium, the Basic Lite
Client package can be used instead of Basic.
Virtualization
Apache HTTP
Version 2.4
Server
PHP Version 5.5
PECL OCI8 Version 2.0 is more recent than the version included with PHP 5.5
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:
For example:
The Zlib extension is needed for the pecl command used below.
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 or libaio1 package, if it is not already present.
http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-12c-2088811.html 1/4
04/06/2018 Installing PHP and the Oracle Instant Client for Linux and Windows - Updated for DB 12c
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, hit Enter and PECL will automatically build and install an oci8.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 since pecl does not expand environment variables.
If you don't have the pecl 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 confirm extension_dir points to the directory the oci8.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 set LD_LIBRARY_PATH to
/usr/lib/oracle/12.1/client64/lib. You might also want to set standard Oracle environment variables such as TNS_ADMIN and NLS_LANG.
If NLS_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
Enabling the PHP OCI8 Extension on Windows
The Instant Client binaries complement PHP's pre-built binaries for Windows.
Install Apache
Download httpd-2.4.9-win32-VC11.zip and modules-2.4-win32-VC11.zip from ApacheLounge
Unzip httpd-2.4.9-win32-VC11.zip and move the unzipped directory to c:\Apache24. Review the ReadMe.txt file.
Install the Visual C++ redistributable client from Microsoft, as mentioned in the Apache ReadMe.txt.
Run Window's cmd.exe as an administrator, e.g. via typing "cmd" in the quick search bar and using Ctrl-Shift-Enter instead of plain Enter. Accept
the "User Account Control" prompt to allow the shell to make changes to the computer.
Install PHP
Download the "VC11 x86 Non Thread Safe" package php-5.5.10-nts-Win32-VC11-x86.zip from windows.php.net/download.
Install OCI8
Follow the DLL link on PECL for the latest OCI8 2.0 extension and download the "5.5 Non Thread Safe (NTS) x86" ZIP file.
The php_oci8_11g.dll library exists for users who have Oracle Instant Client 11g. The php_oci8.dll library can be used with Oracle Instant
Client 10g. Only one of these DLLs can be enabled.
Configure PHP
Copy c:\php-5.5.10-nts-Win32-VC11-x86\php.ini-development to c:\php-5.5.10-nts-Win32-VC11-x86\php.ini
Edit php.ini:
date.timezone = America/Los_Angeles
Use your local timezone name.
extension = php_oci8_12c.dll
Configure Apache
Edit c:\Apache24\conf\httpd.conf:
http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-12c-2088811.html 2/4
04/06/2018 Installing PHP and the Oracle Instant Client for Linux and Windows - Updated for DB 12c
Copy the mod_fcgid-2.3.9/ReadMe.txt example configuration to the end of httpd.conf, adjusting the PHP directory name and adding the
Instant Client directory to the path:
<Files ~ "\.php$>"
AddHandler fcgid-script .php
FcgidWrapper "c:/php-5.5.10-nts-Win32-VC11-x86/php-cgi.exe" .php
</Files>
Restart Apache
Complete the installation by restarting Apache using the system services, under the Control Panel.
<?php
phpinfo();
?>
Load the script into a browser using the appropriate URL, e.g. http://localhost/phpinfo.php. The browser page will contain an "oci8"
section saying "OCI8 Support enabled" and listing the OCI8 options that can be configured in php.ini.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
echo "<table>\n";
while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>".($item !== null ? htmlspecialchars($item, ENT_QUOTES) : " ")."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
The HR demonstration schema user account may need to be unlocked and given a password. This can be done in SQL*Plus by connecting as the
SYSTEM user and executing the statement:
Troubleshooting
Check the Apache error log file for start-up errors.
Temporarily add error_reporting(E_ALL); and ini_set('display_errors', 'On'); to the PHP script so errors are displayed. For security
reasons, switch display_error back off when finished.
Chapter 8 of The Underground PHP and Oracle Manual has a section "Setting the Oracle Environment for PHP on Linux" that discusses ways to
set environment variables. Chapter 10 contains information about commonly seen connection errors.
Oracle's SQL*Plus command line tool can be downloaded from the Instant Client page to help resolve environment and connection problems.
Check SQL*Plus can connect and then ensure the Environment section (not the Apache Environment section) of phpinfo.php shows the
equivalent environment settings.
If the phpinfo.php script does not produce an "oci8" section saying "OCI8 Support enabled", verify that extension=php_oci8_12c.dll is
uncommented in php.ini and that php.ini's extension_dir directive contains the directory with php_oci8_12c.dll. Ensure the correct Windows
redistributable client is installed.
If using Instant Client ZIP files, make sure the two packages are unzipped to the same location. Make sure a symbolic link libclntsh.so points to
libclntsh.so.12.1.
Set all required Oracle environment variables in the shell that starts Apache.
Conclusion
Using Oracle Instant Client and installing PHP OCI8 from PECL provides maximum PHP flexibility, allowing components to be easily installed and
upgraded.
Questions and suggestions can be posted on the OTN PHP or Instant Client forums. The PHP Developer Center contains links to useful
background material.
http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-12c-2088811.html 3/4
04/06/2018 Installing PHP and the Oracle Instant Client for Linux and Windows - Updated for DB 12c
© Oracle Site Map Terms of Use and Privacy Preferências de cookies Ad Choices
http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-12c-2088811.html 4/4