Some of us, maybe a few of us need to setup a PHP webserver on a windows machine. I know you PHP fans are probably disgusted even thinking about PHP on a windows server. Anyways it’s not very easy to setup PHP, but yet it’s not difficult either, you just need to download a bunch of stuff. I setup PHP (without MySQL) on a Windows 2003 Enterprise Server. I needed to access a Microsoft SQL server in my environment so no need for a MySQL server. So this setup describes how to download PHP and the MSSQL extensions to allow you to connect to a remote MSSQL server.
This assumes you’ve already installed IIS for Windows 2003. In this example I’m using x86.
1. First download and install the Microsoft 2008 C++ Runtime. For x86 click here, and for x64 click here.
2. Download, and install the Microsoft FastCGI addon for IIS make sure it’s allowed in the IIS extensions (IIS Manager > Web Service Extensions), and restart the WWW publishing service.
3. Download and install PHP for Windows. I chose 5.2 because at the time of this writing MSSQL extensions weren’t compatible with 5.3 yet (of course I found out the hard way after installing 5.3, and ended up downgrading). You can download the VC9 version (assuming you are using IIS and not Apache). It’s up to you if you want to download the thread safe or the non thread safe. The difference can be found here. For this example I choose non thread safe.
4. Restart the WWW publishing service.
5. Download Microsoft SQL Server Driver for PHP. Put the php_sqlsrv.dll (or php_sqlsrv_ts.dll if you installed the thread safe version of PHP) in the PHP extensions directory (default location will be C:\Program Files\PHP\ext).
6. Now edit the php.ini file in the PHP directory (default location will be C:\Program Files\PHP), and put the following where all the extensions are located at (near the bottom).
Non thread safe: extension=php_sqlsrv.dll
Thread safe: extension=php_sqlsrv_ts.dll.
7. Download and install the Microsoft SQL Server Native Client since my SQL server is remote (normally this would be already loaded if SQL is on the same machine as this server)
7. Restart the WWW publishing service.
8. Now lets verify that PHP and the MSSQL driver are loaded. Create a info.php file in your wwwroot and put the below code in file and save it. Now visit http://localhost/info.php, and you should see PHP information, including if the MSSQL extension loaded. That’s it. Now if you need to find out how to connect to MSSQL through PHP in code, reference the help file that came with the SQL server driver download.
<?php
phpinfo()
?>
Leave a Reply