Installing PHP for IIS on Server 2012/2016/2019 using the Web Platform Installer

Installing PHP on IIS is fairly straight forward using Microsoft’s Web Platform Installer.  Unfortuantely numerous resources available on the web as well as the Web Platform Installer’s prerequisite check overlook a few prerequisites when installing PHP on IIS running on Windows Server. I’ve developed a guide and a list of requirements that will make the process of installing PHP on IIS much easier.

Requirements

Run Windows Update

Install all available updates via Windows Update before continuing. There have been multiple updates in the past that have affected specific components from smoothly installing, specifically .NET Framework. Save yourself the trouble now and install all updates before continuing.

Install IIS role with CGI

The first thing you should do is add the IIS role with FastCGI support. More information on installing IIS and FastCGI can be found on the official PHP website but I’ll cover the basics here.

  1. Click start and type “Server Manager” and then hit enter. This should launch the Server Manager application.
  2. Click Manage Add Roles and Features.
  3. On the Before you being screen, click Next.
  4. Select Role-based or feature-based installation and click Next.
  5. Select the local server and then click Next.
  6. On the Select server roles screen, select Web Server (IIS), click Add Features when prompted to add additional features, and click Next.
  7. On the Select features screen, click Next.
  8. On the Web Server Role (IIS) screen, click Next.
  9. On the Select role services screen, under Application Development, check off CGI. At this point I also recommend checking off any other IIS features that you may require or you’re interested in. I typically check off ASP, ASP.NET, HTTP Redirection and/or Windows Authentication (some of these options will also automatically select prerequisite features as well). Once you have everything you need selected, click Next.
  10. On the confirm installation selections screen, click Install.
  11. Wait for the installation to complete and then click Close. At this point I recommend rebooting the server.

Install .NET Framework 3.5

.NET Framework 3.5 is required for the PHP Manager for IIS application which will install by default when using the Web Platform Installer to install PHP. If you don’t have .NET Framework 3.5 installed on the server, PHP will still install but you’ll be presented with an error regarding PHP Manager – it’s safe to ignore if you don’t need it. With that said, the PHP Manager application can come in handy and I recommend installing it by completing this simple prerequisite.

Although .NET Framework 3.5 can be installed using the Add Roles and Features wizard on Server, it still requires the Windows Server installation media when installing the feature. Before you proceed, obtain the Windows Server installation media and attach it to the server either by physical media or mounting the ISO.

  1. Click start and type “Server Manager” and then hit enter. This should launch the Server Manager application.
  2. Click Manage Add Roles and Features.
  3. On the Before you being screen, click Next.
  4. Select Role-based or feature-based installation and click Next.
  5. Select the local server and then click Next.
  6. On the Select server roles screen, click Next.
  7. On the Select features screen, select .NET Framework 3.5 Features and click Next.
  8. On the confirm installation selections screen, click Specify an alternate source path.
  9. At this point we’ll need the Server 2012 R2 installation media. For example, if you’ve mounted the Windows Server 2012 R2 installation media to D:\, then the path would be D:\sources\sxs. Enter the path to the sources\sxs directory, click OK and then click Install.
  10. Wait for the installation to complete and then click Close. At this point I recommend rebooting the server.

Install Visual C++ Redistributable

The Visual C++ Redistributable is required when installing a default installation of PHP. It will install DLL files that are required by numerous PHP extensions. Without it you will receive HTTP 500 errors and PHP will throw the error “The FastCGI process exited unexpectedly”.

You can download the Visual C++ Redistributable from here. Be sure to grab the 32-bit version (VSU_4\vcredist_x86.exe) as the 64-bit version will not work (or maybe it’s not required?). 

Install the Web Platform Installer

The Web Platform Installer is a small utility by Microsoft which is supposed to make it quicker and easier to deploy web services and deployment tools. But honestly it falls short of expectations. For example, when installing PHP it does not perform a prerequisites check for CGI, .NET Framework 3.5, or the required DLL files (installed by Visual C++ Redistributable). As long as these prerequisites are installed, PHP and the PHP Manager should install successfully.

You can download the Web Platform Installer from here. After the WPI is installed, it will automatically launch. Close it for now.

Install PHP using the Web Platform Installer

Once you’ve installed all the prerequisites you can go ahead and install PHP using the Web Platform Installer.

  1. Click Start and type “Server Manager” and then hit enter. This should launch the Server Manager application.
  2. Select Tools Internet Information Services (IIS) Manager.
  3. Select your server’s name from the navigation tree.
  4. Double click Web Platform Installer under Management.
  5. Enter “PHP” in the search field and select the version of PHP you’d like to install. I recommend the latest version of PHP 7. 
  6. Select Install and accept the terms and conditions. PHP and PHP Manager for IIS should now download and install successfully.

Congratulations. You now have a working IIS Server running PHP meeting all requirements of a default PHP installation. Enjoy!

Troubleshooting

PHP Manager won’t install

I’ve had trouble getting PHP Manager to install on Windows Server 2019. I’ve had much better success with PHP Manager 2. It can be downloaded from here, https://github.com/phpmanager/phpmanager/releases.

PHP Isn’t Working

Create a PHP test file, C:\inetpub\wwwroot\test.php. The contents of the file should include the following:

<?php phpinfo(); ?>

Browse to http://localhost/test.php to see if PHP is loaded and working. If not, try running the script from the command prompt. For example:

"C:\Program Files (x86)\PHP\v5.6\php-cgi.exe" C:\inetpub\wwwroot\test.php

Review and research any errors. I hope this helps!

Leave a Reply