How to Install PHP on Microsoft IIS 7.0 and Later
Help us continue creating free content like this…
This video shows how to install PHP on Microsoft Windows Server/IIS 7.0 and later
Don’t forget to subscribe on YouTube
NOTE: This tutorial was created using Windows Server 2016. Some steps may be slightly different on Server 2008 and Server 2012.
1.) Download the necessary files, which include PHP and the Visual C++ Runtime on a seperate computer, unless you have another browser installed on your server or the advanced security settings disabled in IE. (Everything is pretty much blocked by default in Internet Explorer running on Windows Server).
2.) If you used another PC to download the files, copy them over to the desktop on your server.
3.) Open up the Server Manager and navigate to the Add Roles and Features Wizard.
4.) Check the box for Web Server (IIS).
5.) Click next until you arrive at Role Services and check the box for CGI.
6.) Once IIS installs, just pop open your browser and type – http://localhost to ensure that it is working. If everything installed properly you will be presented with a page that says IIS and the version number.
7.) Navigate back to your desktop where you copied the downloaded PHP and C++ files. Start by installing the Visual C++ Runtime (Even though there is no specified mandatory order, so you could unzip PHP first, it’s up to you).
8.) When the C++ Runtime is done installing, extract the PHP compressed archive. Extract it somewhere convenient such as – C:\php. That is where I have placed it in this tutorial.
9.) Once the PHP files are done extracting, navigate to the folder where the files are located and find – php.ini.production, and rename it to – php.ini. Alternatively, you can download the pre-configured php.ini file I have linked to in the downloads and place that in your php directory.
** If you downloaded the pre-configured php.ini, you can skip the next step. If you opted to do it manually, then DO NOT skip the next step! **
10.) Open php.ini in notepad and change the following:
– Uncomment and set the key, cgi.force_redirect = 0
– Uncomment the key, fastcgi.impersonate = 1
– Uncomment and set the key, extension_dir to the ‘ext’ folder in the path PHP was extracted to (i.e. ‘C:\php\ext’).
11.) Save php.ini and open up IIS under Administrative Tools.
12.) Click your server in the left-hand pane, and then open up – Handler Mappings, in the right-hand pane, and then click – Add Module Mapping.
13.) Fill in the spaces as follows:
– Request path: *.php
– Module: FastCgiModule
– Executable: C:\php\php-cgi.exe
– Name: PHP_VIA_FastCGI (Or whatever you want)
14.) Click OK and then select your server again in the left-hand pane, and then next open up FastCGI Settings. Double click – C:\php\php-cgi.exe to open it up.
15.) Under “General”, click to open up the configuration for Environment Variables (Click the little box with the dotted lines on the right).
16.) Under “Members”, click Add and configure the following:
– Name: PHP_MAX_REQUESTS
– Value: 5000
17.) Click OK to save your changes, exit out of the IIS console and open the command prompt.
18.) From within the command prompt, type – iisreset to restart IIS to make sure all of the changes take effect.
19.) PHP is configured and should be working at this point. Good job! But wait… we want to do one last thing to test it out, so just bear with me for a little bit longer.
20.) Open up Windows Explorer and navigate to the root of the default website for IIS. Most likely it will be – C:\Inetpub\wwwroot. We want to create a new file and name it – phpinfo.php, or you can download it in the downloads above and place it into this directory. If you wish to do this manually, keep following me to the next step.
21.) Once you create the file, open it notepad and type the following on the first line – <?php phpinfo (); ?>, and save the file.
22.) Open up your browser again and type – http://localhost/phpinfo.php. You should be presented with a page that displays information about your PHP installation. If, so you are good to go and ready to move onto deploying your PHP website in Windows, such as WordPress or Drupal. If for some reason this did not work, please make sure to go over every step very carefully to ensure you haven’t missed anything. If something still doesn’t seem right please don’t hesitate to contact me and ask for help!