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:
1 2 3 4 5 6 7 8 9 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>My Test Site</title> </head> <body> <p>This is a test.</p> </body> </html> |
The second file, version.php
, contained a simple test of PHP:
1 2 3 |
<?php echo 'Current PHP version: ' . phpversion(); ?> |
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.1
at the end of file hosts
at folder C:\Windows\System32\drivers\etc
, as follows:
1 2 3 4 |
# localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 127.0.0.1 localhost.testsite.com |
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:
- extracted the archive to
C:\php
; - created a copy of
php.ini-production
asphp.ini
; - added
C:\php
to myPATH
environment variable; and - 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
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
; cgi.force_redirect is necessary to provide security running PHP as a CGI under ; most web servers. Left undefined, PHP turns this on by default. You can ; turn it off here AT YOUR OWN RISK ; **You CAN safely turn this off for IIS, in fact, you MUST.** ; http://php.net/cgi.force-redirect cgi.force_redirect = 0 ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok ; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting ; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting ; of zero causes PHP to behave as before. Default is 1. You should fix your scripts ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED. ; http://php.net/cgi.fix-pathinfo cgi.fix_pathinfo=1 ; FastCGI under IIS (on WINNT based OS) supports the ability to impersonate ; security tokens of the calling client. This allows IIS to define the ; security context that the request runs under. mod_fastcgi under Apache ; does not currently support this feature (03/17/2002) ; Set to 1 if running under IIS. Default is zero. ; http://php.net/fastcgi.impersonate fastcgi.impersonate = 1 ; Disable logging through FastCGI connection. PHP's default behavior is to enable ; this feature. fastcgi.logging = 0 |
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