Installing PHP on Windows 10 and IIS

I’ve always liked PHP for creating dynamic Web pages. I find PHP to be much simpler than ASP.NET for some kinds of Web sites.

However, installing PHP on a Windows machine has always been kind of a pain in the patooty. It is possible install PHP using the Microsoft Web Platform Installer, but I prefer to manually install PHP because if something goes wrong using the Web Installer, it’s very, very difficult to fix, but errors in a manual install are easier to track down.

There are five basic steps to install PHP on a Windows 10 machine:

1. Enable (if necessary) IIS on the machine, and IIS-CGI on the machine.
2. Download and extract PHP to C:\PHP
3. Configure the php.ini configuration file
4. Configure IIS to handle PHP page requests
5. Test everything

So, here we go. My instructions are highly abbreviated and are intended for someone who has a medium amount of familiarity with Windows and IIS.

1. Configure IIS

Control Panel | Programs | Turn Windows features on or off

Check Internet Information Services
Check IIS | World Wide Web Services | Application Development Features | CGI
OK

01_configureiis


2. Install the NTS (non-thread safe) 64-bit version of PHP

Download and save onto the machine:

http://windows.php.net/downloads/releases/php-7.x.x-nts-Win32-VC14-x64.zip

Extract all the contents of the zip file to C:\PHP

02_unzip_php

Now edit the System PATH variable so IIS knows where the PHP executables are:

Control Panel | System and Security | System | Advanced System Settings
Environment Variables
System Variables | Path | Edit
New -> C:\PHP

03_edit_path_variable


3. Configure the php.ini file. This is the part you’d never figure out without some help.

Make a copy of file C:\PHP\php.ini-development and save it as C:\PHP\php.ini

Edit file php.ini by finding the following entries, uncomment them, and change values to:

1. fastcgi.impersonate = 1
2. cgi.fix_pathinfo = 0
3. cgi.force_redirect = 0
4. open_basedir = “C:\inetpub\wwwroot”
5. extension_dir = “ext”
6. error_log=”php_errors.log”
7. uncomment the 24 Windows Extensions entries:

extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_ftp.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_gmp.dll
extension=php_intl.dll
extension=php_imap.dll
extension=php_interbase.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_mysqli.dll
extension=php_oci8_12c.dll
extension=php_openssl.dll
extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
extension=php_shmop.dll

Save the edited php.ini file.

4. Configure IIS to work with PHP

Run | inetmgr
Handler Mappings | Add Module Mapping

Request path: *.php
Module: FastCgiModule (from the dropdown)
Executable (optional): C:\PHP\php-cgi.exe
Name: FastCGI

OK (Yes)

04_iis_handler_mappings


5. Test the installation and configuration

Launch Notepad with Administrative privleges. Create a file test.php and save it at C:\inetpub\wwwroot. The contents are (I use an image because my blog software would choke on HTML text):

file_test_php

Now launch a browser and navigate to

http://localhost/test.php

05_testing

And hopefully it works. There’s a LOT that can go wrong, but by Googling one error at a time you should eventually be able to get a Windows 10 machine with IIS to serve up PHP Web pages.


Advertisements
This entry was posted in Miscellaneous. Bookmark the permalink.