Search This Blog

Sunday, November 25, 2012

How to Install Cakephp in IIS 7.5

During my last project, I used cakephp as my php framework. One of the objective of using cakephp is that you can developed a system on the fly. It has great documentation. unfortunately, when it comes to installing cakephp running on IIS it lacks some documentation. The cookbook is quite frank about needing to do some tweaks to let cakephp run under IIS environment. Fortunately, after a few googles and research, I was able to let the cakephp run in IIS. Heres how.

Prerequisites:
  1. Need to install url rewrite. You can download the url rewrite here
  2. Fresh cakephp
Testing and Installation:
  1. Download and unpacked cakephp in c:\inetpub\wwwroot\
  2. In IIS console under url rewrite, import the .httaccess in cakephp, webroot, and in app folder.
  3. Once imported, IIS will create webconfig file. The webconfig file resides in root directory folder of cakephp. Modified it to show show something like below
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear/>
                 <!--rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^$" ignoreCase="false" />
                    <action type="Rewrite" url="app/webroot/" />
                </rule>
               
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url="(.*)" ignoreCase="false" />
                    <action type="Rewrite" url="app/webroot/{R:1}" />
                </rule-->
               
                 <rule name="Imported Rule 0" stopProcessing="true">
                   <match url="^(img|css|files|js)(.*)$"></match>
                   <action type="Rewrite" url="/cakephp/app/webroot/{R:1}{R:2}" appendQueryString="false"></action>
                 </rule>
                
                 <rule name="Imported Rule 1" stopProcessing="true">
                   <match url="^(.*)$" ignoreCase="false" />
                   <conditions logicalGrouping="MatchAll">
                     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                   </conditions>
                   <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
                 </rule>
                
                 <rule name="Imported Rule 2" stopProcessing="true">
                   <match url="^$" ignoreCase="false" />
                   <action type="Rewrite" url="/cakephp/app/webroot/" />
                 </rule>
                
                 <rule name="Imported Rule 3" stopProcessing="true">
                   <match url="(.*)" ignoreCase="false" />
                   <action type="Rewrite" url="/cakephp/app/webroot/{R:1}" />
                 </rule>
                
                 <rule name="Imported Rule 4" stopProcessing="true">
                   <match url="^(.*)$" ignoreCase="false" />
                   <conditions logicalGrouping="MatchAll">
                     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                   </conditions>
                   <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
                 </rule>
                
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Your cakephp will now work in IIS.

Happy coding