Experiments with IIS and PHP

After many years of hand-tooling HTML, I bit the bullet and installed WordPress. That has sparked an interest in PHP, the server-side scripting language. I needed a local copy to experiment with.

Turning on IIS

First, I needed web server software. The operating system on my PC is currently 64-bit Windows 10 and Windows comes with such software called IIS (Internet Information Services). However, I needed to turn on the IIS feature.

Typing Turn Windows features on or off in to the Windows search pane brings up the Windows Features dialog. I selected the checkbox for Internet Information Services and accepted the default set of features (which includes the CGI sub-feature under the World Wide Web Services and Application Development Features sub-features).

The ‘About’ dialog of the Internet Information Services (IIS) Manager application tells me that has turned on IIS version 10.0.16299.15.

Creating a local web site

By default, IIS uses folders under C:\inetpub. The folder wwwroot contains the simple default web site that IIS serves when http://localhost is entered into a browser.

I created folder testsite under C:\inetpub for a simple web site with two files. (Administrative privileges are required to add files there.) The first, index.html, contained the simplest test page:

The second file, version.php, contained a simple test of PHP:

In the Internet Information Services (IIS) Manager application, I added the web site to the Sites (Actions: Add Website...), specifying the site name (testsite), the physical path (C:\inetpub\testsite) and the host name (localhost.testsite.com).

127.0.0.1 is the loopback Internet protocol (IP) address referred to as the localhost. It is used to establish an IP connection to the same computer being used by the end-user. I added a connection between localhost.testsite.com and 127.0.0.1at the end of file hosts at folder C:\Windows\System32\drivers\etc, as follows:

Installing PHP

I followed the links and instructions on the Download page of the PHP site to download a .zip file for the current stable version of PHP (which was version 7.2.3) that was for 64-bit Windows (x64) and Non-Thread Safe (as recommended for IIS). I then followed the instructions in the install.txt file in the .zip archive and:

  1. extracted the archive to C:\php;
  2. created a copy of php.ini-production as php.ini;
  3. added C:\php to my PATH environment variable; and
  4. restarted my PC.

Configuring PHP for IIS

The PHP Manual includes a page for Microsoft IIS 7.0 and later. I followed the instructions there to configure the following settings in php.ini:

Configuring IIS for PHP

I also followed the instructions in the PHP Manual to use the Internet Information Services (IIS) Manager application to configure the Handler Mappings and the Default Document for the server node.

Handlers process requests for specific file types. Handler Mappings manages a list of such handlers. I added a mapping for the request path *.php, specifying module FastCgiModule and executable C:\php\php-cgi.exe and the restriction that the handler should be invoked only if the request was mapped to a file or folder (Request Restrictions...), and named the mapping PHP_via_FastCGI.

Default Document manages a list of default file(s) to return when a client does not request a specific file, in order of priority. I added index.php to the list, placing it second after index.html.

Result

It worked! Typing localhost.testsite.com in the browser served the simple web page and typing localhost.testsite.com/version.php yielded:

Current PHP version: 7.2.3