By now you should have an Oracle database and Apache/PHP web server installed and working. However, before you can start developing PHP/Oracle applications, you have to enable the OCI8 extension in your PHP installation.
If you have both the database and web server installed on the same computer then you already have all the required Oracle components—no Instant Client is required, and so you can skip to the next section Enabling the OCI8 Extension in an Existing PHP Installation.
However, if you have the database and web server installed on different computers, you will need to install another piece of software, which will bridge the gap between Oracle and PHP. Specifically, you have to install the Oracle client libraries needed by the PHP OCI8 extension.
Consider Oracle Instant Client, a package containing Oracle client libraries required to run OCI, OCCI, and JDBC-OCI applications. Note that Oracle Instant Client comes with a free license for both development and production environments.
You can download a copy of Oracle Instant Client specific to your platform from the Instant Client web page on OTN at:
http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html
From the above page, you should download the Basic Instant Client Package that includes all the files required to run OCI, OCCI, and JDBC-OCI applications.
On Windows, perform the following steps to install the Instant Client Package:
Download a copy of Oracle Instant Client from OTN.
Unzip the package into a single directory in your file system.
Add the path to the directory in which you unzipped the libraries to the PATH environment variable.
On UNIX-like platforms, perform the following steps:
Download a copy of Oracle Instant Client from OTN.
Unzip the package into a single directory in your file system.
Set LD_LIBRARY_PATH to the directory in which you unzipped the libraries.
Once you perform the above steps, you can move on and enable the OCI8 extension in your PHP installation.
On Windows, perform the following steps to enable the OCI8 extension in your existing PHP installation:
In
php.ini
, uncomment the OCI8 extension line:
extension=php_oci8.dll
In
php.ini
, set theextension_dir
directive to the directory in whichphp_oci8.dll
resides:
extension_dir= c:\php\ext
Restart Apache.
On UNIX-like platforms, perform the following installation steps:
Run configure with Apache2 and OCI8 support:
# cd php-5xx # ./configure --with-apxs2=/usr/local/apache2/bin/apxs \ --with-config-file-path=$HOME/apache/conf \ --with-oci8-instant-client=/home/instantclient10_2 \ --enable-sigchild
Rebuild PHP:
# make # make install
/usr/local/apache2/bin/apachectl start
To make sure that the OCI8 extension was successfully enabled, you might run the testphp.php
script discussed in the Testing PHP section earlier in this appendix. This time the output should include the OCI8 section verifying that OCI8 support is enabled.
Most of the examples in this book assume that you will use SQL*Plus when it comes to performing database administration or creating database objects. Note that SQL*Plus is installed by default when you install the Oracle Database software. So, if you are going to use a local database, you don't need to install SQL*Plus since you already have it. Otherwise, you might take advantage of SQL*Plus Instant Client—the SQL*Plus command-line tool that allows you to communicate with a remote database.
To install SQL*Plus Instant Client on your computer, perform the following steps:
Download the SQL*Plus Instant Client Package specific to your platform from the Instant Client web page on OTN at:
http://www.oracle.com/technology/tech/oci/instantclient/ instantclient.html
Unzip the package to the same directory where you unzipped the Basic Instant Client Package files.
Optionally, set a user environment variable
NLS_LANG
to an appropriate value.
Note
The NLS_LANG
parameter is composed of three optional components: language, territory, and character set. To specify it, you use the following syntax: NLS_LANG = language_territory.charset. NLS_LANG
defaults to AMERICAN_AMERICA.US7ASCII
. For information about supported NLS_LANG
settings, see Oracle documentation: Oracle Database Globalization Support Guide.
That is it. Now you can use SQL*Plus Instant Client to connect to a remote database.