I assume you ahve already installed the SQL server and IIS (including CGI feature).

PHP Installation.

  1. Download the latest PHP and WinCache extension to the following link. Php For Windows
  2. Extract .zip file, and rename it php.
  3. Move the folder to C:\. So the full path of the PHP folder will be C:\php
  4. Go to C:\php and copy the C:\php\php.ini-production to C:\php\php.ini
  5. Enable th following extension:
extension=curl
extension=gd
extension=mbstring
extension=pdo_mysql

Windows Cache Extension for PHP installation.

Windows Cache Extension for PHP is a PHP accelerator that is used to increase the speed of PHP applications running on Windows and Windows Server. Once the Windows Cache Extension for PHP is enabled and loaded by the PHP engine, PHP applications can take advantage of the functionality without any code modifications

  1. Follow this link to download this extension: Wincache extension for PHP
  2. Extract or install.
  3. Copy php_wincache.dll to C:\PHP\Ext.
  4. Open the php.ini on C:\php, and add the following:
extension=php_wincache.dll
  1. Recycle the IIS Application Pools for PHP to pick up the configuration changes.

Setting environment variable

In order to work properly, we need to add the C:\php to the PATH in environment variable.

  1. Go to System Properties->Advanded->Environment Variable.
  2. On System Variables click Path->Edit.
  3. Click New and type C:\php.

Configure IIS.

  1. Open the IIS, go to Handler Mappings
  2. Click Add Module Mapping with the following:
Request path: *.php
Module: FastCgiModule
Executable: C:\php\php-cgi.exe
  1. Once done, click ok.
  2. Go to Default Document, and add index.php on it.

Testing PHP on IIS

To ensure the php file is loaded correctly, create a new folder and site on IIS, and create a new index.php file on it. Copy the follwoing code for the testing:

<?php
phpinfo();
?>

Install requirement driver to connect with SQL server.

In order to connect the PHP and SQL server, we need to install the correct SQL-server driver for you php version.

  1. Download the SQL ODBC driver for SQL on the following link Microsoft ODBC Driver 18 for SQL Server (x64)
  2. Download Microsfot Driver for PHP for SQL server on the following link: Microsoft Drivers for PHP for SQL Server (Windows)
  3. Install and Extract both downloaded files.
  4. copy the appropriate version.
  5. On my case, I use php_sqlsrv_82_ts_x64.dll. So I Copy the php_sqlsrv_82_ts_x64.dll to C:\PHP\ext.
  6. Edit the php.ini and add extension=php_sqlsrv_82_ts_x64.dll

Test PHP Code to connect SQL:

Since installation process is done. We can proceed to test the connection. Before creating the php connection script, you can ensure that you already created an account on the SQL or enabling and resseting the SA account Create a connection.php on the PHP site folder, and copy the following. Change database, user and password with the correct name.

<?php
$serverName = 'SQL01';
$connectionInfo = array('Database'=>'dbtestb','UID'=>'sa','PWD'=>'securepassword');
$conn=sqlsrv_connect($serverName,$connectionInfo);

if($conn){
     echo "Connected.<br />";
}else{
     echo "Unable to connect<br />";
     die( print_r(sqlsrv_errors(), true));
}
?>

If you got Connected on the testing page, it means you have succesfully connected to the database.