PHP is one of the most widely used scripting language on the web. It is mostly paired with Apache or Nginx Web Server since both are open source software but there are cases when we need to run PHP on Microsoft's Internet Information Services (IIS) since there are a lot of companies that already using it in their environment.
Microsoft Internet Information Services (Web Server) is part of Windows Server. It is also available on Windows 8 or 10 Pro Version. You just need to activate it which we will discuss later.
To get started, we need to download some software from the web.
*You can download the Non Thread Safe version. Select the zip file. It is the one compatible with IIS.
There are several versions of PHP available for Windows. PHP 5.6, 7.0, 7.1, 7.2 and so on. These are all supported versions of PHP. You can always select the latest version which is 7.2 as of August 2018 unless you have older applications that needs the older version of PHP. It is recommended to update the PHP version as soon as it is released for security and stability.
Microsoft Visual C++ Redistributable
*Download the version of Visual C++ Redistributable based on the version of PHP you are going to use. Refer to the versions below.
Visual C++ 2017 = VC15
Visual C++ 2015 = VC14
*Download the 64 bit version if you are using PHP x64 version.
URL Rewrite (This is the counterpart of mod_rewrite of Apache Web Server)
Install the Visual C++ Redistributable after downloading it by clicking the downloaded executable.
Extract the downloaded PHP file on your local directory. You can place it on C:\PHP or anywhere in your drive as long as you remember the location.
On Windows 10 Pro machine, press the Window Key to open the Start Menu / Search. Type "Turn Windows features on or off".
You will see the window as shown below. Select Internet Information Services. You don't need to install all the features like FTP. Just make sure to install the following features.
- Web Management Tools > IIS Management Console
- World Wide Web Services > Common HTTP Features > (All Items)
Make sure to install CGI under World Wide Web Services > Application Development Features.
Once IIS is completely installed, you can test if it is running by opening your web browser like Microsoft Edge, Mozilla Firefox or Google Chrome and visit localhost. You should see an IIS Welcome Page.
Install the URL Rewrite that we downloaded earlier. Just click the downloaded executable.
Open Internet Information Services (IIS) Manager by searching for it using the Windows Search (Select Window Key then type the search keyword). You can also find it under Control Panel > Administrative Tools > Internet Information Services (IIS) Manager.
Select Handler Mappings.
On the Actions menu located on the right, select Add Module Mapping.
Enter the following info into the fields and click OK. Make sure to replace the Executable path with the path on your local machine where you extracted the PHP earlier.
Add "index.php" under the Default Document. Select your local machine from the left then select Default Document.
The Add button is located on the upper right corner.
The setup of PHP on IIS is now completed. To test if it is working, let's create a "test.php" file inside the webroot of IIS. The default location is C:\inetpub\webroot.
*When creating a PHP file, make sure that the file extension is correct. You don't want to create a file called "test.php.txt". The file extension is hidden by default on Windows. To show it, open any Windows Explorer and select the View menu. Check the File name extensions.
Enter the line below inside the "test.php" file.
<?php phpinfo(); ?>
PHP is now confirmed to work. You just need to modify php.ini to configure PHP and enable extensions that you might need to run your PHP application.