Thought I'd summarize some of the things I've just been doing to get PHP talking Oracle 8, both database and Apache running on a Sun Solaris 8 box. Most of this information is already here somewhere so this is mainly to put it in one place.
Up until this week, my PHP database experience was limited to talking to MySQL. Pretty much a Solaris newbie as well.
<b>The Setup</b>
Operating System: SunOS 5.8 Generic_108528-03 sun4u sparc
Web Server: Apache/1.3.20 (used <a href=http://www.nusphere.com/cgi-bin/nsp.cgi/custsrvc/utils/free_download.htm>NuSphere MySQL package</a>)
Oracle version 8.17 server installed on the same machine as the webserver. Believe (but not certain) you can install the Oracle client and use this to compile PHP as well.
PHP Version 4.0.6
<b>PHP Issues</b>
Although NuSphere comes with PHP, it doesnt include support for Oracle (if you try using PHP Oracle functions you'll be told the function is undefined). So you need to compile a version of PHP with the Oracle functions you need.
For Oracle version 8, you need PHPs <a href=http://www.php.net/manual/en/ref.oci8.php>OCI8 functions</a> and configure PHP before compiling using --with-oci8=$ORACLE_HOME . For older versions of Oracle you need the <a href=http://www.php.net/manual/en/ref.oracle.php>ORA functions</a> and configure PHP --with-oracle=$ORACLE_HOME ($ORACLE_HOME is the environment variable for your Oracle install).
The PHP source code came from <http://www.php.net>http://www.php.net</a>. Once NuSphere was installed, created a directory of PHP "next door" to the nusphere directory and ran;
./configure \
--libdir=../nusphere/apache/php \
--datadir=../nusphere/apache/php \
--enable-inline-optimization \
--enable-magic-quotes \
--enable-trans-sid \
--enable-track-vars \
--enable-bcmath \
--enable-memory-limit \
--enable-wddx \
--enable-sigchild \
--enable-sysvsem=shared \
--enable-sysvshm=shared \
--with-xml \
--with-ttf \
--with-iconv=shared \
--enable-apc=shared \
--enable-exif=shared \
--with-oci8=$ORACLE_HOME \ <<< or --with-oracle=$ORACLE_HOME for versions below 8
--with-tiff-dir \
--enable-gd-imgstrttf \
--with-png-dir \
--enable-ftp=shared \
--with-zlib \
--enable-shmop=shared \
--with-gd \
--with-mysql=../nusphere/mysql \
--with-apxs=../nusphere/apache/bin/apxs \
--with-config-file-path=./ \
--with-ldap=shared \
--with-openssl
This preserves the options NuSphere creates for you and adds Oracle functionality. Had to install locally some of the libraries which can be found from <a href=http://www.sunfreeware.com>http://www.sunfreeware.com</a>.
Used the Gnome compiler to do this.
You may need to add some of the paths of the above libraries to your $LD_LIBRARY_PATH environment variable, to restart Apache.
<b>Environmental Damage</b>
Having stuggled to get that far, next problem is setting up the environment for PHP to use Oracle functions. The ones to worry about are (this applys for Oracle 8 - may not be true for older versions);
$ORACLE_HOME = path to your Oracle install e.g. /ora/oracle/817
$ORACLE_SID = dbname.yourdomain.com the TNS name of your database. TNS is Oracles name service, converting databse names into IP addresses. Using $ORACLE_SID on my system failed to provide PHP with the TNS name of the database I wanted. To find what's in your TNS table, look it $ORACLE_HOME/network/admin/tnsnames.ora (the path may differ a little depending on your install).
$TWO_TASK = dbname.yourdomain.com - This has the same effect as $ORACLE_SID, except that it worked and $ORACLE_SID didnt. Why? I have no idea.
[Replace $ORACLE_HOME below with the path to your install]
ORA_NLS33=>>$ORACLE_HOME<</ocommon/nls/admin/data - specifies the national language Oracle uses (I think)
NLS_LANG=(AMERICAN_AMERICA.US7ASCII) specify a country, name and character set.
LD_PRELOAD=>>$ORACLE_HOME<</lib/libclntsh.so.8.0 - preloads the client library for Apache. Say no more.
LD_LIBRARY_PATH=>>$ORACLE_HOME<</lib So Apache knows where to find the Oracle Libraries.
TNS_ADMIN=$ORACLE_HOME/network/admin - not sure if this is required or not.
You can set these with your PHP script temporarily (for the duration of the script using the putenv function.
e.g. putenv ( "TWO_TASK=yourdb.yourdomain.com" ); - this could be useful for accessing databases on different servers
Or if you set the environment either for the web user or on Apaches start up, your will need to restart apache for it to recognise them.
Now (hopefully) you can run PHPs Oracle functions.
<b>Useful Web Sites</b>
Couple of good tutorials on use of PHPs Oracle functions;
<a href=http://www.thickbook.com/extra/php_oracle.phtml>http://www.thickbook.com/extra/php_oracle.phtml</a>
<a href=http://www.phpworld.com/articles/2000.03/oracle_000.html>http://www.phpworld.com/articles/2000.03/oracle_000.html</a>
Also, check out <a href=http://technet.oracle.com/index.html>http://technet.oracle.com/index.html</a> for information on Oracle (such as the meaning of error codes) and <a href=http://www.db.cs.ucdavis.edu/teaching/sqltutorial/>http://www.db.cs.ucdavis.edu/teaching/sqltutorial/</a> for Oracle SQL - there are some differences to MySQL (note: Oracle has a command line query tool for Unix, sqlplus syntax: sqlplus username/password@tnsname e.g. joebloggs/[email protected] - this can be used to test SQL statements).
Phew.
Hope that helps someone. Feel free to email if you need some help.
Up until this week, my PHP database experience was limited to talking to MySQL. Pretty much a Solaris newbie as well.
<b>The Setup</b>
Operating System: SunOS 5.8 Generic_108528-03 sun4u sparc
Web Server: Apache/1.3.20 (used <a href=http://www.nusphere.com/cgi-bin/nsp.cgi/custsrvc/utils/free_download.htm>NuSphere MySQL package</a>)
Oracle version 8.17 server installed on the same machine as the webserver. Believe (but not certain) you can install the Oracle client and use this to compile PHP as well.
PHP Version 4.0.6
<b>PHP Issues</b>
Although NuSphere comes with PHP, it doesnt include support for Oracle (if you try using PHP Oracle functions you'll be told the function is undefined). So you need to compile a version of PHP with the Oracle functions you need.
For Oracle version 8, you need PHPs <a href=http://www.php.net/manual/en/ref.oci8.php>OCI8 functions</a> and configure PHP before compiling using --with-oci8=$ORACLE_HOME . For older versions of Oracle you need the <a href=http://www.php.net/manual/en/ref.oracle.php>ORA functions</a> and configure PHP --with-oracle=$ORACLE_HOME ($ORACLE_HOME is the environment variable for your Oracle install).
The PHP source code came from <http://www.php.net>http://www.php.net</a>. Once NuSphere was installed, created a directory of PHP "next door" to the nusphere directory and ran;
./configure \
--libdir=../nusphere/apache/php \
--datadir=../nusphere/apache/php \
--enable-inline-optimization \
--enable-magic-quotes \
--enable-trans-sid \
--enable-track-vars \
--enable-bcmath \
--enable-memory-limit \
--enable-wddx \
--enable-sigchild \
--enable-sysvsem=shared \
--enable-sysvshm=shared \
--with-xml \
--with-ttf \
--with-iconv=shared \
--enable-apc=shared \
--enable-exif=shared \
--with-oci8=$ORACLE_HOME \ <<< or --with-oracle=$ORACLE_HOME for versions below 8
--with-tiff-dir \
--enable-gd-imgstrttf \
--with-png-dir \
--enable-ftp=shared \
--with-zlib \
--enable-shmop=shared \
--with-gd \
--with-mysql=../nusphere/mysql \
--with-apxs=../nusphere/apache/bin/apxs \
--with-config-file-path=./ \
--with-ldap=shared \
--with-openssl
This preserves the options NuSphere creates for you and adds Oracle functionality. Had to install locally some of the libraries which can be found from <a href=http://www.sunfreeware.com>http://www.sunfreeware.com</a>.
Used the Gnome compiler to do this.
You may need to add some of the paths of the above libraries to your $LD_LIBRARY_PATH environment variable, to restart Apache.
<b>Environmental Damage</b>
Having stuggled to get that far, next problem is setting up the environment for PHP to use Oracle functions. The ones to worry about are (this applys for Oracle 8 - may not be true for older versions);
$ORACLE_HOME = path to your Oracle install e.g. /ora/oracle/817
$ORACLE_SID = dbname.yourdomain.com the TNS name of your database. TNS is Oracles name service, converting databse names into IP addresses. Using $ORACLE_SID on my system failed to provide PHP with the TNS name of the database I wanted. To find what's in your TNS table, look it $ORACLE_HOME/network/admin/tnsnames.ora (the path may differ a little depending on your install).
$TWO_TASK = dbname.yourdomain.com - This has the same effect as $ORACLE_SID, except that it worked and $ORACLE_SID didnt. Why? I have no idea.
[Replace $ORACLE_HOME below with the path to your install]
ORA_NLS33=>>$ORACLE_HOME<</ocommon/nls/admin/data - specifies the national language Oracle uses (I think)
NLS_LANG=(AMERICAN_AMERICA.US7ASCII) specify a country, name and character set.
LD_PRELOAD=>>$ORACLE_HOME<</lib/libclntsh.so.8.0 - preloads the client library for Apache. Say no more.
LD_LIBRARY_PATH=>>$ORACLE_HOME<</lib So Apache knows where to find the Oracle Libraries.
TNS_ADMIN=$ORACLE_HOME/network/admin - not sure if this is required or not.
You can set these with your PHP script temporarily (for the duration of the script using the putenv function.
e.g. putenv ( "TWO_TASK=yourdb.yourdomain.com" ); - this could be useful for accessing databases on different servers
Or if you set the environment either for the web user or on Apaches start up, your will need to restart apache for it to recognise them.
Now (hopefully) you can run PHPs Oracle functions.
<b>Useful Web Sites</b>
Couple of good tutorials on use of PHPs Oracle functions;
<a href=http://www.thickbook.com/extra/php_oracle.phtml>http://www.thickbook.com/extra/php_oracle.phtml</a>
<a href=http://www.phpworld.com/articles/2000.03/oracle_000.html>http://www.phpworld.com/articles/2000.03/oracle_000.html</a>
Also, check out <a href=http://technet.oracle.com/index.html>http://technet.oracle.com/index.html</a> for information on Oracle (such as the meaning of error codes) and <a href=http://www.db.cs.ucdavis.edu/teaching/sqltutorial/>http://www.db.cs.ucdavis.edu/teaching/sqltutorial/</a> for Oracle SQL - there are some differences to MySQL (note: Oracle has a command line query tool for Unix, sqlplus syntax: sqlplus username/password@tnsname e.g. joebloggs/[email protected] - this can be used to test SQL statements).
Phew.
Hope that helps someone. Feel free to email if you need some help.