PHP on Windows Vista with FastCGI
With the launch of Windows 2008 Beta3 (for which Gattaca is an Early Adopter thanks to an invitation from Microsoft Colombia) we have begun the final phase of migrating our applications to this platform. However, there are some new things in this server that deserve attention. One of them is the native support for PHP and other scripting languages such as IronRuby through a joint initiative by Microsoft and Zend to develop something called FastCGI, which is a new, improved way for CGI multiprocessing.
In this post we will talk about the experience of installing and running PHP applications on IIS7 using FastCGI.
The Environment.
This can be done on Windows 2008 Beta3, which has native FastCGI support, or
On a machine running Windows Vista with IIS7; in this case you must install the FastCGI CTP 2 support available at this link
You also need PHP; it can be downloaded from http://www.php.net/ , although there are people running this with php4, I did it with version 5.2. On this page you can download several versions, but the recommendation is to download the one called PHP 5.2.3 Non-thread-safe Win32 binaries [9,523Kb] – 01 June 2007, this version is optimized to run with IIS7 and FastCGI. (The others also run, and very well, but this one has 30% higher performance according to tests carried out by Microsoft and Zend)
Installation
PHP
Unzip PHP to a path without spaces in the name, for example c:php or d:php, rename the php.ini-recommended file to php.ini, open the php.ini file and change the following variables:
Redirect cgi to false (cgi.force_redirect = 0), modify the extensions path (extension_dir = “D:PHP ext”) (or the path where you put PHP),
You must also create the Environment variables (In Control Panel, System, Advanced System Settings, Advanced Options, Environment Variables). Add the User variable “PHPRC = d:phpphp”, add to the System Path variable the path: “d:phpphp”
With that, PHP should be ready to run in the previous PHP mode and also in the new mode. Some optional variables we configured that could be useful (short_open_tag = On, error_reporting = E_ALL & ~E_NOTICE, upload_max_filesize = 10M, session.save_path = “D:PHPTempSessions”)
Finally, you have to give the IIS Process user permissions on the PHP folder.
FastCGI
Unzip the file you downloaded to some path on the disk, for example D:FastCGI
In the readme.txt file are very simple instructions, which are basically:
Install FastCGI by running from the command console with administrator permissions:
fcgisetup.exe /install
Associate Php with FastCGI:
fcgisetup.exe /add d:phpphp-cgi.exe PHP, (The path where you left PHP)
Done. This should create the necessary modules and handlers in IIS 7.0. To verify it was installed correctly, you should find something like this in your IIS7 administration console.
In the Modules list (by Features view) a native module called iisfcgi pointing to C:Windowssystem32inetsrviisfcgi.dll,
In the handler mappings list (Handlers) a Script mapping called PHP-iisfcgi pointing to your PHP (for example: D:PHPphp-cgi.exe) with a request path pointing to PHP files (*.PHP).
If you have other handlers pointing to *.PHP, you probably already had php running or tried to do something similar to this installation. In our installation we removed the modules and handlers associated with PHP that were not FastCGI. (But before doing this you must correctly understand what the modules and handlers you are removing do and why you are removing them).
If you got this far, everything seems to be properly installed and configured. You can create an application pointing to a directory and create a simple PHP page like this to test (modinfo.php, which contains only “<?php phpinfo(); ?>”. This page, viewed from the browser, should show you the PHP status and on the Server API line indicate:
Server API : CGI/FastCGI
The Application.
Now that you are running PHP applications on IIS7 and with the new, improved, high-performance PHP FastCGI support, you can run your PHP applications. We run Sugar CRM version 4.5.1 on SQL Server. (As Sugar CRM distributors and consultants, it is very useful to be able to offer our clients the product on IIS7 and be ready for when they move to the new Windows 2008 servers. But another important reason for choosing this application is that Sugar has been working with Microsoft for more than a year to offer the best of the open source world on the Microsoft platform: improved support for IIS, optimization for integration with Active Directory, and support for SQL Server (including Express, Standard, and Enterprise) and support for the Microsoft Community License licensing model. (Part of the Microsoft Shared Source Initiative), among other aspects.
In another post we will talk about why this works better than before (the reasons) and how to run Ruby or some other scripting language using FastCGI.
Note: I have to thank Ivan Suárez and German Cárdenas from Gattaca's Commercial Open Source Group, who are experts in PHP and have helped me a lot with the installation, configuration, and understanding of PHP concepts. Thanks, guys.
I hope this helps.
Juan Carlos Peláez
MCTS
KeyWords: PHP, Windows Vista, IIS7, Windows Server 2008 Beta 3, FastCGI, Sugar CRM, Juan Peláez
Need Expert Help?
Let's discuss how I can help with your technical challenges
Schedule a Consultation