I assume you ahve already installed the SQL server and IIS (including CGI feature).
PHP Installation.
- Download the latest PHP and WinCache extension to the following link. Php For Windows
- Extract .zip file, and rename it
php
. - Move the folder to
C:\
. So the full path of the PHP folder will beC:\php
- Go to
C:\php
and copy theC:\php\php.ini-production
toC:\php\php.ini
- 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
- Follow this link to download this extension: Wincache extension for PHP
- Extract or install.
- Copy
php_wincache.dll
toC:\PHP\Ext
. - Open the
php.ini
onC:\php
, and add the following:
extension=php_wincache.dll
- 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.
- Go to
System Properties->Advanded->Environment Variable
. - On
System Variables
clickPath
->Edit
. - Click
New
and typeC:\php
.
Configure IIS.
- Open the IIS, go to
Handler Mappings
- Click
Add Module Mapping
with the following:
Request path: *.php
Module: FastCgiModule
Executable: C:\php\php-cgi.exe
- Once done, click ok.
- Go to
Default Document
, and addindex.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.
- Download the SQL ODBC driver for SQL on the following link Microsoft ODBC Driver 18 for SQL Server (x64)
- Download Microsfot Driver for PHP for SQL server on the following link: Microsoft Drivers for PHP for SQL Server (Windows)
- Install and Extract both downloaded files.
- copy the appropriate version.
- On my case, I use
php_sqlsrv_82_ts_x64.dll
. So I Copy thephp_sqlsrv_82_ts_x64.dll
toC:\PHP\ext
. - Edit the
php.ini
and addextension=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.