How to Use IIS, PHP and Oracle

The common problem with using IIS, PHP and Oracle is incorrect permissions.

The Problem

Your Windows machine has IIS, PHP and Oracle. You create a PHP script using the oci8 extension and it calls PHP5 functions like oci_connect(), oci_parse(), or PHP4 functions like OCILogon() and OCIParse(). You invoke the script and get errors like:
"Warning: ocilogon() [function.ocilogon]: OCIEnvInit() failed."
or
"Unable to load dynamic library php_oci8.dll - Access is denied"

The Cause

As Monty wrote in the OTN Forum

If the IIS is allowed to use the anonymous logon it uses IUSR_<machinename> account to read the files, therefore this user needs to have read access on oracle installation directory.

The Solution

Give it to them.

Here is my annotated version of Tarek Spatz's summary of his solution for IIS 6.0, Oracle 9i, PHP 5.1.2.
  1. Install your Oracle client

  2. The inet-user needs now access rights for the

    • oracle folder
    • oracle\bin folder
    • tnsnames.ora file - if you are using a net alias in oci_connect()  as your database name in PHP.  A net alias is a text string like "PROD1" or "XE" that is defined in a tnsnames.ora file.

    Christian Wenz has a tip in the not-a-bug PHP bug 29835  that

    IUSR_MACHINENAME needs read access to the _complete_ bin directory (be sure to check the "replace permissions" options when setting this).

    You might want to use a dependency checker to verify exactly what access is needed.

  3. Set these Environment Variables in Control Panel -> System -> Advanced -> Environment Variables

    • ORACLE_HOME = "C:\oracle\ora92"
    • NLS_LANG if you use a non default (non-American) language or character set
    • TNS_ADMIN if you are using your own tnsnames.ora instead of the default ORACLE_HOME\network\admin\tnsnames.ora. Set TNS_ADMIN to the directory containing tnsnames.ora; it is not set to the file name.
  4. Restart IIS

    A posting by Andy Hassall says "IIS runs as a child of the IIS Admin service. This then runs as a child of SERVICES.EXE. Processes inherit environment from their parent. Since you can't really stop SERVICES.EXE without the system going tits up, changing the environment seen by IIS without a reboot appears tricky, as changing the environment for your command prompt or the system has no effect on other already-running processes."

I have never used IIS, so this note is simply a summary of suggestions in the links above.  Corrections are welcome.

Update: You may also be interested in my post on Using PHP OCI8 with 32-bit PHP on Windows 64-bit.

Update: There is a comment on how to set the PATH in IIS in this forum post

Comments:

typo: Christain (I do that all the time, myself ;-) )

Posted by Christian Wenz on April 30, 2006 at 11:28 PM PDT #

Fixed. Sorry!

Posted by Christopher Jones on May 01, 2006 at 12:27 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

Tourists looking out over an Opal mine
I'm a Product Manager in Server Technologies, working on scripting languages and developer-access.
Email: christopher.jones@oracle.com
Twitter: http://twitter.com/ghrd
Book: Free PHP Oracle book
Download: PHP Linux RPMs with the OCI8 extension
Links: OTN PHP Developer Center

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today