Awhile ago, I wrote a guide for manually installing PHP on Windows Server 2016, well I tested out that guide but used Server 2019 as the OS.
The Guide remains unchanged, so all I have done is fixed a few grammatical errors and reposted under the new title.
Installing PHP 7 on IIS Server 2019
This guide will take you through installing PHP7 on Server 2016. This is what works for me after following many guides, so I thought I would write my own. PHP is required for many of the Open Source blogging apps or CMS Packages out there, but can be a bit fiddly to install.
I have had success using the IIS web platform components installer, but lately some requirements get left behind and things don’t work, so this is a quick and dirty manual guide.
So what’s needed, hop over to http://windows.php.net and pick up the latest version of PHP which at the time of writing is 7.1. I have used the VC14 x64 Non-Thread Safe version, which is recommended for use on Windows IIS.
Also required is the Visual C++ Redistributables for visual Studio, PHP based on VC14 requires the redistributables indicated below.
When PHP and the VC Redist package is downloaded Install the VC_Redistx64.exe, create a folder in the C drive called PHP7, and extract the downloaded PHP zip file to the folder. Open the PHP7 folder and copy the php.ini-development file and save it as php.ini. Open this file and make the following changes;
Fastcgi_impersonate = 1
cgi.fix_pathinfo = 0 (zero)
extension_dir = “ext”
error_log = “c:\php7\php_errorslog”
Timezone = UTC (Or your time zone)
Enabling PHP Modules.
Further down the php.ini file we need to “un” comment loadable module that php requires to function
Un comment out following lines under Dynamic Extensions; then save the file. These are the minimum required if using a CMS with MySQL.
Add PHP to the Environment Variable Path statement
Click Environment Variables…
Select Path and then Edit…
Select New, this allows you to input a new “path variable” into the path, Type C:\PHP7
If desired you can move the new entry up the list. This will put it closer to the start of the Path variable, but is not necessary.
Click OK, OK, OK. Restart the server
A quick check that things are on track can be achieved by opening PowerShell and and typing php –info
If you get a screen full of output, like below, then things are looking good
Install IIS ensuring the CGI option is selected
Some features may need the Server OS DVD in the drive or the ISO mounted if doing this in a Virtual Machine as an alternate source path is needed to be specified for some features. The scrip here will install all the features and roles BUT, assumes your CD/DVD is Z:\ and that you have either, a second partition on your drive labelled as D:\ or a second drive installed, labelled as D:\ Edit the script as necessary. Some things the script does is to create a new Inetpub\wwwroot folder on D:\ and copies all the c:\inetpub\wwwroot data to the new folder then deletes the C:\inetpub\wwwroot. IF you don’t have a second drive or partition configured parts of the script will fail.
Add a Module Mapping
Once IIS is installed, open up IIS Manager and open the Handler Mappings.
Double click Handler Mappings
On the right hand side menu, select Add Module Mapping
Fill in the required information
Select Request Restrictions…
Ensure the following selections are as shown
On the Mapping Tab
On the Verbs Tab
On the Access Tab
Click OK, OK
When presented with the CGI application notification
Restart the Server
When the server is back up and running, create a text file with the following
Save this file in the Inetpub\wwwroot folder as Index.php ensure there is no .TXT extension. When saving the file as shown
Add Index.php top the IIS Default Document list.
Open IIS Manager, select the Server, and then select Default Document
Double click Default Document
Click Add…In the Add Default Document type Index.php, click OK
The new default document will appear in the list of documents.
Now it’s time to test our install. Open a web browser and go to http://localhost/ all being well you should be presented with the php configuration output
That’s it, your server is now configured to deliver pages using PHP