Sunday, September 16, 2012

IIS and PHP

It is quite handy to have PHP hook up with IIS server that I can develop PHP applications on a window platform. In this article, I am going to share the integration process and some useful tutorials.

The Specs of my computer

  • Window 7 Ultimate Service Pack 1
  • IIS (Internet Information Service) Version 7.5
  • PHP Version 5.3.17 VC9 x86 Non Thread Safe

1. Download/Install IIS and PHP

If you haven't had IIS server and PHP installed in your computer, ( The way I found I didn't have IIS in my computer is when I search  "iis", "Internet Information Services (IIS) Manager" is not on the list. )
The most handy way is go to http://php.iis.net/ , click on "Install PHP Now",
you will be prompted to download Microsoft Web Platform Installer. Using this installer, as it says, you are able to download "Internet Information Services (IIS), SQL Server Express, .NET Framework and Visual Web Developer" in a easier way.

If you already have IIS ( for example, you had installed ASP.NET development framework in your computer, then it is very likely that you already have IIS), you only need to install PHP
Download/Install PHP for Windows
http://windows.php.net/download/
Download PHP 5.3 VC9 x86 Non Thread Safe Installer is recommended.

2. Enable FastCGI Support in IIS

Start --> Control Panel --> Programs--> Turn Windows features on or off (under Programs and Features)
check CGI (under Internet Information Service --> World Wide Web Services)
























3. Change PHP Settings

After installation of PHP, edit the php.ini file. This file, in my case, is in c:\Program Files (x86)\PHP\

fastcgi.impersonate = 1
fastcgi.logging = 0
cgi.fix_pathinfo=1
cgi.force_redirect = 0

4. Create a handler mapping for PHP

Open IIS Manager (you can search "iis" and select Internet Information Services Manager),
and click on "Handler Mappings"
























Click on Add Module Mapping in the left action panel and filled in the following properties:
  • Request path: *.php
  • Module: FastCgiModule
  • Executable: C:\[Path to PHP installation]\php-cgi.exe
  • Name: PHP_via_FastCGI
Click on Request Restrictions, choose the Mapping tab, check "Invoke handler only if request is mapped to:", and select "File or folder".

  

5.  Launch/Test Web application

So far, the settings for IIS and PHP are finished. If you already has developed some web applications in PHP and you want to test it.

Add Web Application
Open IIS Manager --> right click on "Default web site" in the right connections panel --> choose "Add application" -->type in Alias and choose the Physical path, the directory in which your web pages reside --> click "OK"

Launch Web App
In IIS Manager, click on "Start" in the right actions panel (under the Manager Web Site section)
Then click on "Browse *:80 (http) in the right actions panel (under the Browse Web Site section)
The IIS welcome page appear, type in localhost/your_app_name/*.php

If You don't have web pages to test ......
You can fabricate a phpinfo.php page in the physical directory you set up for the application or 
in the C:\inetpub\wwwroot folder

[Notice] you might not have write permission to the directory C:\inetpub\wwwroot\ , to save a file in that folder, you have to change security properties of it.
The content of phpinfo.php

<?php
phpinfo();
?>

Type in the link to browse the PHP information 
localhost/phpinfo.php or localhost/your_app_name/phpinfo.php


Useful Tools / Tutorials

One tool that you can easily manage your PHP settings (instead of manually editing php.ini) is download PHP Manager for IIS
Which provides an easy way to manage PHP version, settings and install extensions in IIS.

Basically, I follow this tutorial 
"PHP, Microsoft IIS 7.0 and later" as the most important guideline.
http://www.php.net/manual/en/install.windows.iis7.php





----------------------------------
Add notes 2013/6/17
1. You might encounter error messages like "you do not have permissions to view this page" when you try to browse your webpage. Then, you need to change the permission of the folder where your web pages reside.
Right click on the folder, in the "Security" tab, Edit permission and add "IUSR", grant it Read, Execute rights.

2. In installing the PHP, when it asks you "Select the web server you wish to setup", choose "IIS FastCGI"















 

No comments:

Post a Comment