Setting Up a Zend Framework Application on IIS
Saturday, May 15, 2010
There are several problems associated with running Zend Framework applications on IIS. This post looks at how to address these problems.
- The application itself needs to be stored in an appropriate location, such as C:\Websites\mysite. This will contact the application, public and library directories. The public directory may have a different name, such as htdocs, depending on the target system.
- You need to create a virtual host with the name of the application (e.g. mysite), which points at the public directory (e.g. C:\Websites\mysite\public).
- The framework works best when used with URL rewriting. There is a standard rewriting module on Apache, called mod_rewrite. For a long time there was no such standard extension for IIS. However, Microsoft has developed IIS URL Rewrite, which provides the necessary functionality. To make use of this, you need to download and install the extension from here.
- Then you need to add the following web.config file to the public directory:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Imported Rule 1" stopProcessing="true"> <match url="^.*$" /> <conditions logicalGrouping="MatchAny"> <add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="" ignoreCase="false" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" pattern="" ignoreCase="false" /> </conditions> <action type="None" /> </rule> <rule name="Imported Rule 2" stopProcessing="true"> <match url="^.*$" /> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
- Finally, you need to set the default document for the directory to index.php.
- Because you typically set up a virtual host as a subdirectory of the default website, e.g. http://localhost/mysite, you should make sure that you use the correct base for all the URLs in your application. To that end, you can use the Base URL view helper, which comes with the Zend Framework as standard. For instance, if your contact page is reached via a request for /contact, you can make sure that the link is given the correct prefix as follows:
<p>Click <a href="<?php echo $this->baseUrl('/contact'); ?>">here</a> to contact us.</p>
The above should ensure that the application you develop runs in the same way on IIS as it would on Apache.

Practical Web 2.0 Applications with PHP (Expert's Voice) by Quentin Zervaas
Beginning Databases with PostreSQL: From Expert to Professional 2nd Edition: From Novice to Professional by Neil Matthew, Richard Stones