IIS Support For PHP

Adrian Jenkins
4 min readMar 6, 2023

--

Install Latest PHP Version (8.2)

This version of PHP requires C++ Redistributable for VS 2019 (at least)

Microsoft Visual C++ Redistributable for Visual Studio 2022

Download for corresponding OS.

You can also use this link:

PHP Download

Download corresponding OS and use the Non Thread Safe.

Unzip it under “c:/php”:

Testing PHP Installation

Check installation by opening command prompt and change directory to “c:/php”

Microsoft Windows [Version 10.0.17763.3770]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\azureuser>cd C:\php
C:\php>php.exe --version
PHP 8.2.1 (cli) (built: Jan 3 2023 23:36:33) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies

IIS Configuration

CGI Configuration

We need CGI module.

If you are installing IIS for the first time you can use the following command:


Install-WindowsFeature -name Web-WebServer, Web-CGI -IncludeManagementTools

We must indicate IIS where is the CGI for ‘.php’ files. All PHP code will be executed by this CGI.

  1. Open IIS Manager, select the hostname of your computer in the Connections panel, and then doubleclick Handler Mappings.
  2. In the Action panel, click Add Module Mapping.
  3. In Request path, type “*.php”.
  4. From the Module menu, select FastCgiModule.
  5. In the Executable box, type the full path to Php-cgi.exe, for example C:\PHP\Php-cgi.exe.
  6. In Name, type a name for the module mapping, for example FastCGI.
    Click OK.

Default Document Configuration

Add “index.php” and “default.php” into “Default Document” module. So, if anyone visits
“localhost/wordpress”, if there is a file called with one of those names, it will be automatically served.

  1. Select the hostname of your computer in the Connections panel, and double-click Default Document.
  2. In the Action panel, click Add. Type Index.php in the Name box, and then click OK.
  3. Click Add again. Type Default.php in the Name box, and then click OK.

PHP Manager Extension

PHP Manager extension help us to configure IIS for PHP.

PHP Manager

Before using it we need to make sure we have that file. Let us go to where we unzipped PHP content. In our case C:/php

Make a copy of “php.ini-production”, just to have it.

Rename “php.ini-production” => “php.ini”

Close IIS Manager and open it again, you should now see a new icon:

Open the module and “View recommendations”

You could check all boxes, I am going to check the followings:

WinCache extension [Optional]

The Windows Cache Extension for PHP is a PHP accelerator that is used to significantly increase the speed of PHP applications running on the Windows® operating system.

Download WinCache Extension for PHP

Extract files in “C:\php\ext”:

Enable extension in the “php.ini”

Environmental Variables [Optional]

Open the environmental Variables

Add the path where php is.

In my case “C:\php”:

Testing PHP Inside IIS

1. Open a text editor, for example Notepad, as Administrator.

2. In a new file, type the following text:


<?php phpinfo(); ?>

3. Save the file as C:\inetpub\wwwroot\Phpinfo.php.
4. Open a browser and enter the following URL:

http://localhost/phpinfo.php

A nicely formatted webpage is displayed showing the current PHP settings.

Resources

--

--