X

The leading edge of scripting languages and Oracle Database brought to you by the Data Access Development team

  • php |
    May 1, 2006

How to Use IIS, PHP and Oracle

Christopher Jones
Senior Principal Product Manager
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

Join the discussion

Comments ( 2 )
  • Christian Wenz Monday, May 1, 2006
    typo: Christain (I do that all the time, myself ;-) )
  • Christopher Jones Monday, May 1, 2006
    Fixed. Sorry!
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services