Category Archives: Wamp

Windows, Apache, MySQL & PHP

PHP, SQL Server with IIS

Installing & Configuring PHP with IIS

Download the Windows binary of PHP 5 from Unzip it to, say, C:\PHP. Open the “php.ini-dist” in C:\PHP and save it as “php.ini”. Locate the following line in php.ini:                         ; cgi.force_redirect = 1

We need to uncomment this line and change the setting to ‘0’ to run PHP under IIS, as shown below:

cgi.force_redirect = 0

Click Start -> Control Panel -> Administrative Tools -> Internet Information Services:


Select Default Web Site, right-click on it and select Properties:


Select the Home Directory tab and click on Configuration. In the Application Configuration window, select Mappings and click on the add button.


Enter the executable as C:\PHP\PHP-CGI.EXE and the extension as .php, as shown below.  


Click on OK button. This configuration enables IIS to run PHP files using PHP interpreter.  Finally, right-click on My Computer, select Properties, select Advanced tab and click on Environment Variables. In System Variables, select Path and click on Edit button. Add these paths to the variable value:                        C:\PHP;C:\PHP\EXT

Click OK to finish.



Configuring PHP with SQL Server  PHP supports SQL Server with a set of mssql_xxx functions. The PHP extension directory (normally \PHP\EXT) contains all the database libraries, like php_mssql.dll for SQL Server. Open php.ini. Verify that the “extension_dir=” points to the folder in which the database libraries are stored, as shown below:extension_dir = “c:\php\ext”

Next, look for the line “;extension=php_mssql.dll” in php.ini. Uncomment this line. It tells PHP to load the php_mssql.dll extension library into memory, which makes the mssql_xxx set of functions available to us.  You need the SQL client tools installed on the Web Server. The minimum requirement is the file “ntwdblib.dll”, which can be located in the \Windows\System32 folder on your SQL Server. Copy it to \Windows\System32 folder on your Web Server.  Now restart your web server, IIS. Create a file called “test.php” in notepad and enter the following:$server=”Beta”;$username=”sa”;$password=””;$sqlconnect=mssql_connect($server, $username, $password);$sqldb=mssql_select_db(“opus”,$sqlconnect);$sqlquery=”SELECT order_no FROM Orderlines;”;$results= mssql_query($sqlquery);while ($row=mssql_fetch_array($results)){echo $row[‘order_no’].”<br>\n”;}mssql_close($sqlconnect); 

Save the file in the web server folder “c:\Inetpub\wwwroot”. Open Internet Explorer and type the URL:           


Here Alpha is the Web Server and Beta is the Database Server. The above URL returns the query results on the browser. It is possible to execute SQL statements as well as Stored Procedures of SQL Server in a similar manner. 


Installation and Configuration

You have Windows XP or Vista. Download the other packages from their respectives sites:

  1. Apache from
  2. MySQL from
  3. PHP from

Download the latest stable versions. In this section, we are using Apache 2.0.55, MySQL 5.0.18 and PHP 5.1.5.

After installing Apache, you may see the files in the folder C:\Program Files\Apache Group\Apache2\. The web pages are stored in “htdocs” sub-folder and the configuration files are stored in “conf” sub-folder. You may save your web pages in a new folder “c:\htdocs”. In this case you need to modify the “httpd” file in “conf” folder to make these changes:

DocumentRoot “C:/htdocs”

<Directory “C:/htdocs”>

Open a browser and type


If the Apache is installed properly, you will see a screen as shown below:

There are two main ways to install PHP for Windows: either manually or by using the installer. Once you have PHP installed on your Windows system, you may also want to load various extensions for added functionality.

Try the PHP 5.1.5 installer downloaded. It will install PHP into C:\PHP. You may see a screen to choose the Server Type from a number of options, which include web servers like PWS, IIS, Apache and Xitami.


Unfortunately, I was asked to configure the web server manually, when opted for Apache. Let us do that!

Unzip the downloaded PHP 5.1.5 zip file into the C:\PHP folder. Open the file “php.ini-recommended” and save it as “php.ini” to your Windows folder (e.g., C:\Windows). Copy “php5ts.dll” to any path mentioned in PATH environment variable (e.g., C:\Windows\System32).

At his point of time, Apache does not recognize PHP pages. If you load the test page now in your browser, you will get a screen similar to the following, since Apache does not get the help of PHP to interpret the page:


Now modify Apache configuration file httpd to reflect the following lines:

 LoadModule php5_module “c:/php/php5apache2.dll”

AddType application/x-httpd-php .php

Restart Apache web server. Test the page “test.php” with your browser. If the installations are correct, you may get a screen similar to the following:


Scroll down the page. There is much information available on the PHP setup on Apache. Note that we have now a database engine called “sqlite” as part of the PHP.

Next install the full fledged database MySQL 5.0.18. The installation will complete the service configuration as well, so that Windows will start MySQL as a service. Once the installation is over, you may try the command line client. It will appear as shown below:


Again, configure PHP to talk to MySQL. Open php.ini (in C:\WINDOWS) and make the following modifications:

1. Find “extension_dir” and modify it to show the directory in which the loadable extensions (modules) reside.

extension_dir = “c:\php\ext”

2. Locate Windows extensions and uncomment the line which reads:

                        Extension = php_mysql.dll

3. In order to use PHP’s session functions, you need to modify session save path as shown here:

session.save_path = “c:\windows\temp”

Finally, add C:\PHP as a path in Windows system environment variable PATH. Otherwise, while Apache tries to load php-mysql.dll, it may show an error warning like this:

“PHP Startup: Unable to load dynamic library ‘php_mysql.dll’ –

The specified module could not be found.”

If everything is done right, if you again test the page “test.php” in your browser, you will see screens with MySQL variables defined as shown below: