How to Use IIS, PHP and Oracle
By cj on Apr 30, 2006
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"
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 SolutionGive 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.
Install your Oracle client
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.
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.
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."
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