• Speed up your WordPress Blog on IIS 7 by using WP-Super-Cache

    Date: 2009.04.26 | Category: WordPress | Tags: ,

      Since I moved my Blog to an IIS 7 server outside main­land China, I found it became ter­ri­bly slow than before on a LAMP (Linux+Apache+MySQL+PHP) Server. I tried to find out why my site was so slow run­ning on IIS and wan­ted to change this situation.

    Tur­ning all posts and pages into sta­tic html files is a good way to ext­re­mely speed up my blog. It is common to install a plu­gin named “WP-Super-Cahce” for the action. But unfo­r­tu­na­tely, there was always some­thing wrong in my WP and that plu­gin doesn’t work at all times. I fixed the pro­blem today and want to share my expe­rience with you all. Let’s start!

    If you are a blo­g­ger and your blog is based on an IIS 7 envi­ron­ment, I think this arti­cle maybe helpful for you. I succe­ssfu­lly insta­lled WP-Super-Cache plu­gin on my IIS 7 website after solving some ugly pro­blems. Let’s make our blog faster and faster runing on Win­dows Server!

    Install and Con­fi­gure WP-Super-Cache

    There are 10 easy steps to get cached con­tent on your IIS or Apa­che server under Windows:

    1. Down­load plugin.

    2. Ext­ract it so you have a /wp-content/plugins/wp-super-cache/ dire­ctory with all the files (like wp-cache.php) in there.

    3. Copy /wp-content/plugins/wp-super-cache/wp-cache-phase1.php to
        /wp-content/advanced-cache.php

    4. Open up /wp-content/plugins/wp-super-cache/wp-cache.php and locate this:
        [sou­r­ce­code language=“php”]function wp_cache_check_link() { glo­bal $wp_cache_link, $wp_cache_file;[/sourcecode]
        Replace that with [sou­r­ce­code language=“php”]function wp_cache_check_link() { glo­bal $wp_cache_link, $wp_cache_file; if ( file_exists($wp_cache_link) ) return true; else { echo “advanced-cache.php does not exist”; echo “Create it by copying $wp_cache_file to $wp_cache_link on your server”; return false; } [/sourcecode]

    6. Add the follo­wing rew­rite rule to the web.config file loca­ted at the root folder of Wor­dP­ress site. Make sure that the “WP Super Cache” rule is before the Wor­dP­ress rule for pre­tty per­ma­links. Typi­ca­lly the <rew­rite> section will look as below:

    <rew­rite>
    <rules>
      <rule name=“WP Super Cache” stopProcessing=“true”>
        <match url=”^(\d{4})/(\d{2})/(.+?)/?$” ignoreCase=“false” />
        <con­di­tions>
          <add input=”{REQUEST_METHOD}” negate=“true” pattern=“POST” ignoreCase=“false” />
          <add input=”{QUERY_STRING}” negate=“true” pattern=”.*=.*” ignoreCase=“false” />
          <add input=”{QUERY_STRING}” negate=“true”
                    pattern=”.*attachment_id=.*” ignoreCase=“false” />
          <add input=”{HTTP_COOKIE}” negate=“true”
                   pattern=”^.*(comment_author_|wordpress|wp-postpass_).*$” ignoreCase=“false” />
          <add
            input=”{DOCUMENT_ROOT}\wp-content\cache\supercache\{HTTP_HOST}\{R:1}\{R:2}\{R:3}\index.html”
            matchType=“IsFile” />
        </conditions>
        <action type=“Rewrite”
             url=“wp-content/cache/supercache/{HTTP_HOST}/{R:1}/{R:2}/{R:3}/index.html” />
      </rule>

      <rule name=“Wordpress Pre­tty Per­ma­links” patternSyntax=“Wildcard”>
        <match url=”*” />
        <con­di­tions>
          <add input=”{REQUEST_FILENAME}” matchType=“IsFile” negate=“true” />
          <add input=”{REQUEST_FILENAME}” matchType=“IsDirectory” negate=“true” />
        </conditions>
        <action type=“Rewrite” url=“index.php” />
      </rule>
    </rules>
    </rewrite>

    Note: this rule exa­mple is con­fi­gu­red to work with Wor­dP­ress per­ma­links that use “Month and name” for­mat, e.g. http://wordpress/index.php/2008/12/sample-post/. If you use any other per­ma­link for­mat then the rule will need to be adju­sted for that.

    If you are using per­ma­link style like “/%post_id%.html”, please use the follo­wing configuration:

    <rule name=“WP Super Cache” stopProcessing=“true”>
        <match url=”^([0–9]+).html$” ignoreCase=“false” />
        <con­di­tions>
            <add input=”{REQUEST_METHOD}” negate=“true” pattern=“POST” ignoreCase=“false” />
            <add input=”{QUERY_STRING}” negate=“true” pattern=”.*=.*” ignoreCase=“false” />
            <add input=”{QUERY_STRING}” negate=“true”
                      pattern=”.*attachment_id=.*” ignoreCase=“false” />
            <add input=”{HTTP_COOKIE}” negate=“true”
                     pattern=”^.*(comment_author_|wordpress|wp-postpass_).*$” ignoreCase=“false” />
            <add
              input=”{DOCUMENT_ROOT}\wp-content\cache\supercache\{HTTP_HOST}\{R:1}.html\index.html”
              matchType=“IsFile” />
        </conditions>
        <action type=“Rewrite” url=“wp-content/cache/supercache/{HTTP_HOST}/{R:1}.html/index.html” />
    </rule>

    In addi­tion, if you want to cache your front page like index.php, please add an rule in the front of “WP Super Cache” rule, just like this:

    <rule name=“WP Super Cache Index Page” stopProcessing=“true”>
        <match url=“index.php” ignoreCase=“false” />
        <con­di­tions>
            <add input=”{REQUEST_METHOD}” negate=“true” pattern=“POST” ignoreCase=“false” />
            <add input=”{QUERY_STRING}” negate=“true” pattern=”.*=.*” ignoreCase=“false” />
            <add input=”{QUERY_STRING}” negate=“true”
                      pattern=”.*attachment_id=.*” ignoreCase=“false” />
            <add input=”{HTTP_COOKIE}” negate=“true”
                     pattern=”^.*(comment_author_|wordpress|wp-postpass_).*$” ignoreCase=“false” />
            <add
              input=”{DOCUMENT_ROOT}\wp-content\cache\supercache\{HTTP_HOST}\index.html”
              matchType=“IsFile” />
        </conditions>
        <action type=“Rewrite” url=“wp-content/cache/supercache/{HTTP_HOST}/index.html” />
    </rule>

    7. Add the follo­wing line into the wp-config.php file above the “require_once(ABSPATH.’wp-settings.php’);” line:

    define( ‘WP_CACHE’, true );

    8. Log into your dashboard and ena­ble WP Super Cache in the Plu­gins page.

    9. Go to the WP Super Cache options page and ena­ble caching.

    10. If you have mod_gzip, mod_deflate, or IIS dyna­mic con­tent caching ena­bled, make sure you don’t ena­ble Super Cache gzip because it’s already being done on the server level (which is better, anyway! :) )

    After that 10 steps, you may find your blog become faster than before. Please open a post and see the sou­rce file code. If that plu­gin is suce­ssfu­lly run, you may find the follo­wing con­tents at the bottom of the sou­rce code:

    <!– Dyna­mic Page Served (once) in x.xxx seconds –>

    If you see that message, Congratulations!

    Make it rea­lly works for you if you meet extra problems

    But in some cir­cu­mstance, you will get fai­led. Because some of your plu­gin prevent WP-Super-Cache from working.

    You may see that message instead:

    <!– Page not cached by WP Super Cache. No clo­sing HTML tag. Check your theme. –>

    Don’t worry about your theme, it may not your theme’s fault. If you’ve seen “</html>” in that sou­rce code page, it should be some pro­blems cau­sed by one or more of your other plu­gins. They may have some conflicts!

    For my site, I found my ano­ther plu­gin named Sta­tP­re­ssCN is con­fli­cted with WP-Super-Cache. You may try to dea­ctive all your plu­gins and active them one by one while seeing the html sou­rce code to check which plu­gin is not fit for your WP-Super-Cache. After fin­ding out the con­fli­cts, you can decide which plu­gin you need more and give up another.

    Try to do that and enjoy your faster blog site and your blo­g­ger life!

    –Paul

     

    Some refer­rence for my article:

    • Share/Bookmark