In this article you’ll learn how to install PHP on Windows Server IIS. With the Windows Cache Extension for PHP (WinCache). WinCache enabled PHP gives you great performance for WordPress, Drupal and Joomla websites, and decreases CPU usage. In this post I’ll show you it’s not hard to set up a high performing PHP stack on Windows Server (IIS). So, let’s optimize our PHP hosting on Windows Server! Show
Install PHP and WinCache on IISthis is an older article that I’ve rewritten. Therefore not all version numbers are up to date and at the time of this writing (March 2020), a stable WinCache version for PHP 7.4 is not available. Where possible I’ll try to use the latest PHP 7.3 versions. What is the Windows Cache Extension for PHP (WinCache)? WinCache is a great addition for your PHP configuration on Windows Server as it provides caching for high performance PHP application hosting in IIS ;-) Want to see the effect of Wincache on a site? See my post The WinCache effect: Save with object caching. However, over the years, problems were reported with either the installation and configuration of the Windows Cache (WinCache), or even with buggy versions. Just search forums.iis.net for examples. And this is why I created this how to install and configure WinCache for PHP on IIS guide. Setting up PHP and WinCache is absolutely not that difficult. Where possible, I show you how to use the IIS Manager GUI and AppCmd and PowerShell commands. You can also follow this guide if you want to install PHP in IIS without Wincache!
Remember that the IIS FastCGI extension provides thread safety, therefore we use non thread safe (NTS) versions of our software. Protip: Never try to set up a new configuration in a live environment! Always use a development-, testing- and staging PHP environment before deploying your PHP configuration to your live PHP hosting environment. This may go very bad when you haven’t tested your set-up. Download and configure PHP and WinCacheDownload PHP and WinCache in a few steps:
WinCache versions Configure PHP and WinCache settingsI always provide a dedicated php.ini file for Wincache enabled websites called php.wincache.ini. I recommend you do the same. You can configure PHP and WinCache in a few short steps (WinCache configuration below the list items):
While you’re at it, tune PHP realpath_cache_size and OPcache too. WinCache’s opcode cache is deprecated in favor of Zend Opcache (php_opcache). On Windows Server, PHP OPcache gives a great performance boost too, if you’ve optimized its configuration properly. Protip: Don’t turn off CURLOPT_SSL_VERIFYPEER to fix issues with SSL, fix your PHP configuration. PHP is now configured to use WinCache, if we set the handler for it in IIS. We created a different PHP configuration file called Disable WinCache
Or you may just change back to your default IIS PHP handler and WinCache is disabled too. How to set up a PHP handler using IIS ManagerOpen up the FastCGI Settings feature of the web server in IIS Manager. IIS Manager FastCGI SettingsIn the Actions pane, click Add Application… Set up PHP as a FastCGI application
You can tweak other settings, such as Instance MaxRequests and Max Instances later. After a while when the server is running smoothly. Don’t start over-optimizing your IIS web server configuration too soon. Open up the Hint: by setting OPENSSL_CONF is your third environment variable, and equally important. It configures OpenSSL properly so you don’t have to turn off CURLOPT_SSL_VERIFYPEER in your scripts. Seet OPENSSL_CONF environment variable to FastCGINow, open up the Handler Mappings feature in IIS Manager. Scroll down to Fill out the requested information. The pipe (|) is important, the full Executable becomes Now click the Request Restrictions… button. Set the handler Request Restrictions to invoke the handler only if request is mapped to File. If you forget this step, you may leave your webserver open to a nasty ASP.NET source code disclosure vulnerability and you may receive “No input file specified.” errors instead of a 404 Not Found page. Request RestrictionsClick OK twice (in the Request Restrictions screen and Edit Module Mapping) to exit. In the next screen, you may click NO to not set up a FastCGI application, because we already manually did. AppCmd to set up FastCgi and PHP configurationIn addition, command-line gurus may use AppCmd to configure FastCGI applications and PHP handlers. I’m not going to post all AppCmd commands here, they’re already in older posts like here and here. Some AppCmd commands you might need when setting up PHP and FastCgi on the command-line:
In
PowerShell, escape the single quote
Troubleshooting PHP configuration on IISTip: use the command-line! Sometimes things go wrong. It just does, for example when you make a typo. That is not a problem. You can very easily troubleshoot PHP configuration errors on the command line. Just run
WinCache opcode cache with PHPWith the release of WinCache version 1.3.5 for PHP 5.5, the WinCache opcode cache ( Conclusion running PHP with WinCache in IISIn this post I showed you how easy it is to install PHP with WinCache on IIS. This creates a high performance web stack to host high volume PHP-based web sites. However, caution is called for: Enabling WinCache for all hosted websites (as default) may run a server out of memory easily, if settings are not optimized. This is because Windows IIS reserves the configured amount of memory per website, and you should monitor IIS memory usage. Note: script engines on OS partition: it’s beyond the scope of this post to explain the dangers of having websites and/or script engines on the same partition as the Operating System! If you develop PHP and MySQL based web sites, you can even use WinCache to cache MySQL query results. This is a turbo boost for your website because the website doesn’t have to create a connection to the back-end database for every request. The WinCache functions are easily ported to APC, and vice versa, and thus you are not stuck on one hosting platform. |