Host PHP on Windows IIS

Host PHP on Windows IIS

It may not seem like a logical choice to run PHP on IIS, but it may make sense. Fortunately, it’s not very hard to get PHP running on IIS and it gives you access to all the great PHP work this community has done.

PHP Introduction

Originally PHP was a personal home page acronym, but now PHP is short: Hypertext Processor. PHP is a web development programming language also called as scripting language. It is also used as the name for that application’s underlying engine.

This is normally the Zend Engine. Although there are alternatives, the Zend Engine is the standard implementation and the only one considered “complete feature.”

The Zend Engine interprets the PHP code and compiles it to a format that it can execute on – the-fly. This may seem inefficient, and it would be if the engine had to do so for every request, but for most use cases, some smart people created optimizations as adequate workarounds. Incidentally, in this article we’re going to look at one such solution (WinCache). PHP’s advantages (such as a great community and fast results) outweigh the potential performance drawback that most users won’t notice.

IIS Introduction

Microsoft’s web server IIS (Internet Information Services) has been around since 1995. The latest version, IIS 10, is Windows-bundled and as such, IIS is a free product. There is a lightweight IIS version called IIS Express which can be installed separately but only for development purposes.

IIS Express supports only HTTP and HTTPS protocols and supports only local requests by default. I’m going to use the full version of IIS 10 in this article.

IIS has had a modular architecture since version 7, enabling us to add only the features we need. In IIS 10 has added HTTP/2, HSTS and container support.IIS is the third most popular web server (after Apache and Nginx), running approximately 8.7% of all websites.

Reasons to deploy PHP on IIS

Most PHP applications run on a web server Apache or Nginx, but there are valid reasons for choosing IIS over other options:

  • More experience with IIS is available to your system engineers.
  • You have a great Microsoft support contract.
  • ASP.NET or classic ASP applications consumer.
  • Locally on IIS, you develop Windows-only solutions and need to work on PHP solutions as well.
  • You need to integrate Active Directory, Windows file shares, or Microsoft Exchange with other Windows services.

IIS runs on Windows only, but remember that running PHP on IIS is not the same as running PHP on Windows. PHP can be run on Windows such as XAMPP or WampServer. These two options, however, provide you with some additional choices. They run Apache as a web server and use as a database server MySQL or MariaDB.

Maybe that doesn’t fit your needs. If you already have websites running in IIS, running your PHP websites there is also a good idea. They’re all in one place in this way. You might even want to use a different database technology. Or you prefer Microsoft’s big company providing the reliability of a solution. We’re going to look at installing PHP on IIS, and you’re going to see it’s not that difficult.

Configure IIS

You will need to activate it if your machine is not running IIS yet. How to do it depends on your specific Windows version. This is usually done in the “Turn Windows features on or off” dialog on a Windows non-server edition.

The easiest way to open this dialog (on Windows 8 and up) is by opening the Start menu and searching for “windows features.” This dialog should then be opened. Check “Internet Information Services” and “CGI” after the dialog is opened.

Host PHP on Windows IIS

More steps are involved on Windows Server. Open the application Server Manager and go through the wizard “Add Roles and Features.” Select “Web Server (IIS)” from the server roles page:

Host PHP on Windows IIS

When prompting server roles to be selected, be sure to enable CGI:

Host PHP on Windows IIS

Once you have installed IIS, you should use the default IIS page to navigate to http:/localhost:

Host PHP on Windows IIS

CGI or FastCGI

CGI is short for the Common Gateway Interface and is a standard web server protocol for running server applications. In your IIS instance, it is important to enable CGI.

In our case, this means that the incoming web request is received by IIS and then passed on to our PHP engine (a simple executable for Windows). Then the PHP engine returns the output to the client that IIS should return.

For each request, CGI starts and stops the application. In terms of performance, this can become quite expensive if you receive many requests. Also, CGI can not handle reuse of database connections or caching in memory very well.

FastCGI is a newer and better CGI version created to address these issues in the mid-90s. Over multiple requests, FastCGI can keep processes alive and reuse other resources, making it a faster and more modern alternative to “classic” CGI. By default, if you activate CGI for IIS, it will include FastCGI. Then IIS executes PHP through FastCGI.

Configure PHP on IIS with Web PI

Using the Web Platform Installer from Microsoft is the easiest way to install PHP on IIS. Web PI is a free package management tool for the installation and dependency of non-commercial web development tools. You can select the latest version of PHP under the Products section of the Frameworks section when running this tool:

Configure PHP on IIS with Web PI

Web PI will add several items (three in my case) to the install list; then click on the big Install button below. Next, you’ll have to accept the different component license terms. If any components are not installed, you may need to manually install them. In my case, there was a problem with the IIS PHP Manager that I just downloaded and installed (from here).

PHP can also be manually installed if you want more control.

Configure PHP on IIS manually

Installing PHP for IIS with Web PI will install it in “C:\Program Files.” You may want more control over this, which is completely possible and not that difficult.

First of all, download PHP from the website of PHP. Be sure to download a secure version that is non-thread. Thread-safety checks are not necessary for PHP, as FastCGI ensures a single-threaded environment.

Removing these inspections improves performance. Extract the files to your chosen folder; for example, “C:\PHP.” Add this folder to the variable Path System.

Next, open the IIS Manager screen for Handler Mappings:

Installing PHP on IIS manually

You can select “Add Module Mapping” in the Actions panel. Enter the necessary details to tell IIS that php-cgi.exe should run * .php files via FastCGI:

Installing PHP on IIS manually

Now select your server in the IIS Manager’s Connections panel and select “Default Document.” In the subsequent Actions panel, click “Add…” and add “index.php.” You can also add other files, such as “Default.php”.

This tells IIS to search for such a file if there is no file specified in the URL. Finally, go to your PHP folder (e.g. “C:\PHP”) and rename “php.ini-development” to “php.ini-production” depending on your environment.

Configuring PHP Manager on IIS

If you are using Web PI to install PHP on IIS, the defaults are likely to be fine, but checking does not hurt. You definitely want to check the configuration if you have installed PHP manually. You can open and edit the “php.ini” file if you know how to configure PHP.

In IIS Manager, you can also open the PHP Manager. Install PHP Manager for IIS from here if you haven’t already.

Then in the IIS Manager you’ll see it:

Configuring PHP Manager on IIS

You will see a warning about your php.ini file immediately when you open it. Clicking on the link “View Recommendations” will provide you with an easy way to fix any problems:

Configuring PHP Manager on IIS

WinCache and PHP extensions

PHP allows for the installation and enabling of extensions. I already had 40 extensions installed in my default installation. Under your PHP installation folder, you can install PHP extensions in the “ext” folder. You can also use the PHP Manager to install them. Likewise, by editing the php.ini file or using the PHP Manager, you can enable and disable extension.

WinCache, for example, is a popular extension to enhance PHP speed on Windows systems. It includes mechanisms for caching such as user data cache, session cache, file system cache, and relative path cache.

If you installed PHP using Web PI, there’s nothing you’ll need to do here. Download the correct version from SourceForge and save it to some temporary folder if you have installed PHP manually.

Be sure to download from the development folder, as the remaining files are for WinCache’s Web PI version. Execute the file “exe” and copy the file “php wincache.dll” to the folder “ext” in the installation folder of your PHP.

You can then click on the link “enable or disable an extension” in PHP Manager and activate WinCache:

WinCache and PHP extensions

The other option at the end of your “php.ini” file is to add “extension= php wincache.dll.” Make sure you download the version of WinCache that matches your version of PHP.

WinCache was only supported up to PHP 7.2 when I wrote this article, although PHP 7.3 was already released. You can read that support for 7.3 is on the radar in the WinCache forums, but it requires some work.

Test PHP Configuration

We can test it easily now that we have installed PHP for IIS. Create a new file and add only the following line to your favorite text editor:

<?php phpinfo(); ?>

Save to C:\inetpub\wwwroot this file. This is where your websites will be hosted by IIS. Make sure you run your editor as an administrator, or you can’t save the file to that folder.

Now navigate your browser to http:/localhost/phpinfo.php and see a long overview of all current PHP settings:

WinCache and PHP extensions

Keep in mind that it is a bad security practice to put a phpinfo.php file on a public website. It exposes too much information that hackers might use to attack you about your server.


Not many people know that IIS supports PHP applications running and how easy it is to set it up. You can get it to work with Web PI in just a few clicks. It’s not too hard to install it manually, and it gives you some extra control.

Linux and Apache or Nginx seem to be PHP’s default choice, but you can run your PHP applications on your IIS web server in just a few steps.

If you don’t have the option to run Apache or Nginx for whatever reason and feel “stuck” with IIS, or just prefer IIS, you shouldn’t stop using PHP’s power, which is still the most popular language on the internet.