Guide to Getting PHP 5 to work with IIS with Custom Identity
When you want PHP running in Microsoft Internet Information Services (IIS) to be able to read/write files on a Windows network share, you could run into a myriad of errors and problems. Hopefully this article will help you get everything working smoothly.
Here what we want is to have IIS run as a Domain user who has the proper access to the network share.- After you have installed PHP (in ISAPI mode), go to the IIS Manager, Application Pools, right-click on DefaultAppPool (or the name of your application pool), and select Properties.
- Go to the Identity tab and type in the User name and Password for the Domain user. Don't forget to prefix the username with the Domain. For instance (and for our example's sake):
MY_DOMAINmy-userClick OK and you will be asked to confirm the password again.
In your PHP script make sure that you escape backslashes for the network share you're trying to get to. For instance if you're trying to do a "opendir" on "\\my_server\my_files", you would do:
$dh = opendir("\\my_server\my_files");
Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\your_script.php
Then you must make sure that you've enabled the module (in this case extension=php_mysql.dll) in php.ini. If you did, it could well be that PHP is not reading the php.ini for some reason. You can make sure by looking at the output of php_info() and look for "Loaded Configuration File". If it says "(none)", then there's a problem. Make sure that "MY_DOMAIN\my-user" (in our example) has read permissions to the php.ini file AND the directory in which it resides- whether it be C:\PHP or C:\Windows.
If you have trouble executing commands using exec(), passthru(), etc, and the script seems to hang, make sure you have given the proper permissions to cmd.exe. So make sure that c:\windows, c:\windows\system32, and cmd.exe all can be read and executed by, in our example, MY_DOMAIN\my-user.
Good luck and I hope this guide helps. These instructions could work for other PHP and Microsoft Internet Information Server (IIS) versions as well, though I used PHP 5.2 and IIS 6.