Running Code in PHP From IIS Server

PHP Running on IIS Server:
Improved performance and greater reliability for PHP applications is ensured by the FastCGI component for IIS6 and iis7

First step: Install PHP :
you can choise do it either by Zip File Installation or Windows Installer.[To use the Zip file installation, follow the instructions in Using FastCGI to Host PHP Applications on IIS 7.0 and Above.]
        you can choose the following  package :  VC14 x64 Non Thread Safe

2. Unpack the files to a directory of your choice (for example, C:\PHP) on your IIS server. We recommend to rename the Php.ini in low-case.
php4

3. you may want to open php.ini on text editor and then uncomment and modify the following settings:
a. Set fastcgi.impersonate = 1.  FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.
b. Set cgi.fix_pathinfo=0  The cgi.fix_pathinfo provides PATH_INFO/PATH_TRANSLATED support for Common Gateway Interface (CGI). Setting this to 1 will cause PHP CGI to fix its paths to conform to the specification.
c. Set cgi.force_redirect = 0.
d. Set open_basedir to point to a folder or network path where the content of the Web site(s) is located.
e. Set extension_dir to point to a location where PHP extensions reside. For PHP 5.2.X, this is typically extension_dir = "./ext" .
f. Set error_log=”C:php_errors.log” This can help with troubleshooting.
g. Enable the required PHP extension by un-commenting corresponding lines. More information follows in the section:
extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_gmp.dll
extension=php_intl.dll
extension=php_imap.dll
extension=php_interbase.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_mysqli.dll
extension=php_oci8_12c.dll
extension=php_openssl.dll
extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
extension=php_shmop.dll

4. you may want to add on System Variables Path  on Windows the  " c:/php" .
php6

5.
 Start IIS Manager by clicking on Start, Programs, Administrative Tools, and then Internet Information Services (IIS) Manager. From the IIS Manager, click on the hostname of your server in the Connections panel on the left. Double-click on the Handler Mappings icon. and then add the  extensio of php to be executed by CGI module and the right cgi-php path in my case C:\php\php-cgi.exe .
PHP2

6. créate a website which name I named was php and set the phisical path where  on a notepad you can add this lines as a test to verify if this Works as expected or not. <?php phpinfo(); ?>   and then save it as c:\inetpub\wwwroot\phpinfo.php
php3
PHP

7.  you may want to add phpinfo.php on Default documents before running the test.

8.  Restart IIS server and then let us give it a try  pointing to that site which file name is phpinfo.php .
php5
 
Remarks:
PHP.INI File Settings
The Php.ini file provides PHP with configuration and environmental information. Below are a number of settings for the Php.ini file that help PHP work better with Windows.
Required Settings:
  • extension_dir = <PATH TO EXTENSIONS> The extension_dir needs to point to the directory where the PHP extensions are stored. The path can be fully qualified (for example, C:\PHP\ext) or relative (for example, .\ext). Extensions that are specified lower in the Php.ini file need to be located in the extension_dir. If the extensions specified are not in the extension_dir, then PHP will give a warning message at the start of script execution, and the application may show errors because of the missing functionality.
  • extension = xxxxxx.dll For each extension enabled, a corresponding extension= directive that tells PHP which extensions in the extension_dir to load at startup time is necessary.
  • log_errors=On PHP errors can also go through the PHP error logging facility. This can be used to send errors to a file or to a service (for example, syslog) and works with the error_log directive described below. When running under IIS, log_errors must be enabled with a valid error_log. Otherwise, FastCGI considers any startup messages (which may be benign) as an error condition, which generates an HTTP 500 return error code to the browser.
  • error_log=<path_to_error_log_file” The error_log needs to specify the fully qualified, or relative, path to the file where the PHP error log is stored. This file needs to be writable for the IIS service. The most common places for this file are in various temporary directories (for example, C:\inetpub\temp\php-errors.log). That puts the log in a place that IIS can use, and also keeps the log close to where PHP applications are running.
  • cgi.force_redirect = 0 This directive is required for running under IIS. It is a directory security facility required by many other Web servers; however, enabling it under IIS will cause the PHP engine to fail on Windows.
  • cgi.fix_pathinfo = 1 This lets PHP access real path info following the CGI specification. The IIS FastCGI implementation needs this extension set.
  • fastcgi.impersonate = 1 FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.
  • fastcgi.logging = 0 FastCGI logging should be disabled on IIS. If it is left enabled, then any messages of any class are treated by FastCGI as error conditions, which will cause IIS to generate an HTTP 500 exception.

Note: This article uses information from IIS on PHP  by Tali Smith  
https://php.iis.net/
https://msdn.microsoft.com/es-bo/en-en/library/hh994592(v=ws.11).aspx
To understand PHP Performance using Windows cache for PHP dll please refere here:
https://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/use-the-windows-cache-extension-for-php