How to install PHP on an IIS Web Server

I recently found a piece of software that I am exploring to help me manage our current IT environment. To install this I require two applications setup. A PHP web server and a MySQL database.
Following below is an example of how to:
Install IIS with PHP on a Windows 2019 Server.

Install IIS

Once the server is installed browse to server manager and choose
“Add Roles and Features”:

Server Manager
Add Roles and Features
IIS

Click next until you get the “Server Roles” and choose the option
“Web Server (IIS)”.
An Option will appear to include Management tools click “Add Features”.

Server Manager
Add Roles and Features
Server Roles
IIS

Add Features

Server Manager
Add Roles and Features
Server Roles
Add Features
IIS

Continue to click next until you get to “Role Services” Browse to “Application Development” Expand it then add the option for “CGI”.
If you are interested in creating a Company Directory from your Domain controller you can choose ASP as well.

Server Manager
Add Roles and Features
IIS
CGI

Click next and install and wait for is to complete. To test it open the web browser on the machine you installed it on and browse to http://localhost/
If you get an Internet Information Services page the installation was successful.

IIS
LocalHost
Internet Information Services

Install Microsoft Visual C++

Before actually installing PHP you install Visual C++. It is quick and easily opens the EXE click Agree and Install.

Microsoft Visual C++

Install PHP

To install PHP you extract the zip file you downloaded to a directory of your choosing. I suggest creating a directory in one of the Program Files directory’s so not to delete it by accident if you clean your root directory’s one day. For this, I extracted it to the C:\ root as this is just a demo Server.

PHP

Once extracted browse to the folder and rename the file php.ini-production to read only php.ini.

Edit the newly named file and amend the following Lines.
Remember to make sure the directory location corresponds to where you extracted the files.

Old ValueNew Value
;cgi.force_redirect = 1 cgi.force_redirect = 0
;fastcgi.impersonate = 1 fastcgi.impersonate = 1
;extension_dir = “./” extension_dir = “C:\php\ext”

Configure PHP in IIS

The last steps is to tell IIS where to find PHP and how to use it.
Open IIS browse to the server and choose Handler Mappings.

IIS
Handler Mappings

Add Module Mapping and fill in the Mapping as per the below screenshot.

IIS
Handler Mappings
Add Module
PHP
CGI

Click ok to save then browse back to the IIS Server page.
Choose FastCGI Settings.

IIS
PHP
FastCGI Settings

Click Collection then add. Fill in the following details:

IIS
PHP
PHP_MAX_REQUESTS

Restart IIS by opening Command Prompt in administrator mode
Type iisreset and Enter.

CMD
IISreset
IIS

Test PHP

To test PHP browse to the IIS root directory and create a new file called phpinfo.php.

phpinfo
PHP

In the new file type the following code Exactly :

phpinfo
PHP

Browse to http://localhost/phpinfo.php if you get a screen as per the below you successfully installed PHP.

localhost
PHP

********************************************************

If you liked what you read Please Share.
I’d love it if you followed me on YouTube and Facebook.

Also, feel free to subscribe to my posts by email.
Donations for the site can be made here.
Thanks for reading.

Spread the love

Leave a Reply

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