Installing PHP for IIS 7 on Windows Server 2008R2

 

  • Download non-thread based PHP 7 from windows.php.net. (I used version php-7.1.5-nts-Win32-VC14-x64)
  • Extract all files to C:\PHP
  • Rename php.ini-production to php.ini and make following changes:
    • Uncomment and set: cgi.force_redirect = 0
    • Uncomment and set: fastcgi.impersonate = 1
    • Uncomment and set: extension_dir = “ext”
  • Add ;C:\PHP to Windows Environment PATH Variable: Control Panel > System > Advanced System Settings > Environment Variables > System Variables > Path
  • Try running php.exe -v from command prompt. You should get something like this:
    • If you get error (in the command prompt) “php.exe is not recognized as an internal or external command, operable program or batch file.” – make sure C:\PHP PATH System variable was entered correctly and restart the server.
    • If you get Windows pop-up prompt with error “php.exe – The program can’t start because VCRUNTIME140.dll is missing from your computer. Try reinstalling the program to fix this problem.” – Download and install Microsoft Visual C++ 2015 Redistributable (x64).

  • Using Windows Server Manager install IIS7 Web Server Role and make sure you include CGI Service.
  • Open Internet Information Services (IIS 7) Manager, click on Server name, open FastCGI Settings, and then click on Add Application:
    • Full Path: C:\PHP\php-cgi.exe
    • Environment Variables > Add (…)
      • Name: PHP_MAX_REQUESTS
      • Value: 10000
    • Instance Max Requests: 10000
    • Standard error mode: ReturnStdErrIn500
      For testing / troubleshooting php errors you can temporary set it to: IgnoreAndReturn200.
    • Save changes.
  • Still in IIS 7 Manager open Handler Mappings and click on Add Module Mapping:
    • Request Path: *.php
    • Module: FastCgiModule
    • Executable: C:\PHP\php-cgi.exe
    • Name: PHP
    • Save changes
  • Open command prompt and restart IIS (iisreset)
  • That should be it. Websites hosted on IIS 7 should now run PHP applications.

 

To install PEAR Repository libraries check this article.

Here are some optional php.ini configuration changes I did for my particular installation (run iisreset for changes to take affect):

  • Uncomment: extension=php_gd2.dll – Enabled GD2 image processing library (for securimage captcha, etc.)
  • Uncomment extension=php_mysqli.dll – Enabled MySQL / MariaDB integration
  • For testing purposes only set display_errors = On (may also need to set Standard error mode to IgnoreAndReturn200 in FastCGI Application settings)

 

May 2017
Windows Server 2008R
Internet Information Services 7 (IIS7)
PHP 7.1.5


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *