Sunday, March 13, 2016

Configure PHP & MySQL on IIS (Windows) — Step‑by‑Step Guide

This blog describes the installation and configuration of PHP, MySQL and IIS (Internet Information Services) server for running web applications on Windows.

Table of contents

  • Overview
  • Prerequisites
  • IIS installation (screenshots)
  • MySQL installation
  • PHP installation and php.ini changes
  • Configuring PHP with IIS (FastCGI)
  • Verifying PHP + MySQL (phpinfo)
  • Installing Joomla (optional)
  • Firewall and external access
  • Troubleshooting

Overview

Internet Information Services (IIS) is a web server from Microsoft. Modern IIS can host PHP and MySQL-backed applications, but unlike WAMP you install and configure each component separately. This guide walks through installing IIS, MySQL, and PHP, and configuring them to work together.

Prerequisites

  • Administrative access on the Windows machine.
  • IIS available on your Windows edition (note: IIS is not supported in Starter, Home Basic, or Home Premium editions). IIS is available in Windows 7 Professional/Ultimate, Windows Server editions, and above.
  • Internet access to download installers and runtimes.

IIS Installation

If IIS is already installed, skip this section. Otherwise enable IIS from Windows Features (or use Server Manager on Windows Server).

STEPS TO CHECK WHETHER IIS IS ALREADY INSTALLED ON YOUR COMPUTER:

  1. Open Control Panel → Programs and Features → Turn Windows features on or off and check Internet Information Services.

To install IIS, follow the Windows feature dialogs. The article screenshots below show the Windows feature dialogs and options during installation.

IIS Check / Step 1

IIS Install Step 2

IIS Install Step 3

IIS Install Step 4

IIS Install Step 5

IIS Install Step 6

IIS Install Step 7

IIS Install Step 8

Note: You can also use the Windows PPI/launcher to install packages: https://sites.google.com/site/karjolblogs/downloads/wpilauncher.zip?attredirects=0&d=1

MySQL Installation

There are a couple of options for installing MySQL on Windows: extract the zip and run manually, or use the MySQL Installer to install as a Windows service. Downloads are available at: http://dev.mysql.com/downloads/mysql/

I chose the MySQL Installer 5.6 for Windows in my setup and used the Custom setup type to install the server, MySQL Workbench and the Notifier. If you install Workbench, you may need the Microsoft Visual C++ 2013 Runtime:

MySQL Installer

After installation, verify you can connect using MySQL Workbench or the MySQL Command Line Prompt.

MySQL Workbench / verify login

You can create the required database using the commands mentioned in the MySQL User Manual.

PHP Installation

Download the Windows PHP build from http://windows.php.net/download. For IIS you should use the non-thread safe (NTS) build and extract it to a folder of your choice (for example C:\php). In this article I used PHP 7.0.

After unzipping, copy and edit the php.ini-production file (rename to php.ini) and place it in C:\Windows (or keep it in your PHP directory and point IIS to it using environment variables — but the simplest approach is to copy to C:\Windows as shown below).

Open php.ini in a text editor and make these minimum changes (uncomment and set values):

cgi.force_redirect = 0
fastcgi.impersonate = 1
; set extension_dir to the ext folder in your PHP install:
extension_dir = "C:\php\ext"
; set timezone
date.timezone = "Your/Timezone"

Set date.timezone to your server timezone (example: America/New_York). See the PHP timezone list at: http://php.net/manual/en/timezones.php

PHP extensions for MySQL

In order for PHP to work with MySQL, enable the appropriate Windows extensions. Note: if you are using PHP 7 or newer, the old php_mysql.dll extension was removed. Use mysqli or PDO instead. Example lines to enable:

extension=php_curl.dll
extension=php_mbstring.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll  ; optional, for PDO

The php_curl.dll extension is often required by applications (for example WordPress) to fetch remote updates.

You can also use the wpilauncher.exe mentioned above to help automate installation.

Configuring PHP and MySQL with IIS (FastCGI)

After setting up PHP, configure IIS to run PHP via FastCGI.

  1. Ensure the CGI feature is installed for IIS (Server Manager → Add Roles/Features → Web Server (IIS) → Application Development → CGI).
  2. In IIS Manager, add a Handler Mapping for PHP with these values:
  • Request path: *.php
  • Module: FastCgiModule
  • Executable: full path to php-cgi.exe (for example C:\php\php-cgi.exe)
  • Name: PHP
  1. Restart IIS after the handler mapping change.

Verifying PHP + MySQL

Create a file phpinfo.php in your site root (wwwroot) with the following content:

<?php phpinfo(); ?>

Browse to http://localhost/phpinfo.php. The PHP settings page should load; search the page for MySQL / mysqli / PDO sections to confirm that PHP has the MySQL extensions loaded.

phpinfo MySQL section

Installing Joomla (optional)

The author includes a packaged Joomla.exe for quick setup. If you use it, the steps below summarize how I proceeded:

Joomla in WebMatrix

Find the port assigned to the site in WebMatrix (note it for external access).

Find port in WebMatrix

Click on the site in WebMatrix to open it (screenshot):

Open site

After updating configuration.php with the DB credentials and restarting IIS, the Joomla site should run.

Firewall and external access

To let other hosts access your site you must allow incoming connections on the port used by the site (commonly TCP 80 for HTTP). Example steps for Windows Firewall with Advanced Security:

  1. Open Windows Firewall with Advanced Security.
  2. Inbound Rules → Action → New Rule
  3. Choose Predefined and select: World Wide Web Services (HTTP)
  4. Allow the connection and finish the wizard.

You can then access the site with:

http://<server-ip>:<port>

Troubleshooting

  • If phpinfo() does not show MySQL sections, confirm the extension_dir path and that the listed extensions are present in C:\php\ext.
  • If you get 500 errors, check the Windows Event Viewer (Application) and the IIS log files for FastCGI/PHP errors.
  • Permission issues: ensure the IIS user (e.g. IIS_IUSRS) has read access to the PHP folder and to your site files.
  • If using PHP 7+, do not enable php_mysql.dll — use php_mysqli.dll and php_pdo_mysql.dll.

Notes and further reading

That's it — Happy Coding.

No comments: