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

    Sin­ce I moved my Blog to an IIS 7 server outsi­de main­land Chi­na, I found it beca­me ter­ri­bly slow than befo­re 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 chan­ge this situa­tion.

Tur­ning all posts and pages into sta­tic html files is a good way to ext­re­me­ly speed up my blog. It is common to insta­ll a plu­gin named “WP-Super-Cahce” for the action. But unfo­r­tu­na­te­ly, the­re was alwa­ys 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 sha­re my expe­rien­ce with you all. Let’s sta­rt!

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 websi­te after solving some ugly pro­ble­ms. Let’s make our blog faster and faster runing on Win­do­ws Server!

Install and Configure WP-Super-Cache

The­re are 10 easy ste­ps to get cached con­tent on your IIS or Apa­che server under Win­do­ws:

1. Down­load plu­gin.

2. Ext­ra­ct it so you have a /wp-con­ten­t/plu­gin­s/wp-super-cache/ dire­cto­ry with all the files (like wp-cache.php) in the­re.

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 loca­te this:
    [sou­r­ce­co­de language=“php”]function wp_cache_check_link() { glo­bal $wp_cache_link, $wp_cache_file;[/sourcecode]
    Repla­ce that with [sou­r­ce­co­de language=“php”]function wp_cache_check_link() { glo­bal $wp_cache_link, $wp_cache_file; if ( file_exists($wp_cache_link) ) retu­rn true; else { echo “advanced-cache.php does not exi­st”; echo “Crea­te it by copying $wp_cache_file to $wp_cache_link on your server”; retu­rn false; } [/sourcecode]

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

<rew­ri­te>
<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­lin­ks” 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­re­ss per­ma­lin­ks that use “Mon­th 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”, plea­se use the follo­wing con­fi­gu­ra­tion:

<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, plea­se 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:

defi­ne( ‘WP_CACHE’, true );

8. Log into your dashboa­rd 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 becau­se it’s alrea­dy being done on the server level (whi­ch is better, anyway! :))

After that 10 ste­ps, you may find your blog beco­me faster than befo­re. Plea­se open a post and see the sou­r­ce file code. If that plu­gin is suce­ssfu­lly run, you may find the follo­wing con­ten­ts at the bottom of the sou­r­ce code:

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

If you see that messa­ge, Cong­ra­tu­la­tions!

Make it really works for you if you meet extra problems

But in some cir­cu­mstan­ce, you will get fai­led. Becau­se some of your plu­gin prevent WP-Super-Cache from wor­king.

You may see that messa­ge instead:

<!– Page not cached by WP Super Cache. No clo­sing HTML tag. Che­ck your the­me. –>

Don’t wor­ry about your the­me, it may not your theme’s fau­lt. If you’ve seen “</html>” in that sou­r­ce code page, it shou­ld be some pro­ble­ms cau­sed by one or more of your other plu­gins. They may have some con­fli­cts!

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 whi­le seeing the html sou­r­ce code to che­ck whi­ch plu­gin is not fit for your WP-Super-Cache. After fin­ding out the con­fli­cts, you can deci­de whi­ch plu­gin you need more and give up ano­ther.

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

-Paul

 

Some refer­ren­ce for my arti­cle:

You may also like...

4 Responses

  1. poniDurb says:

    Niksdo­ta 3 It is dou­btful.

    _____________
    leve­t­ra
    car­toon
    3

  2. Repo­rt inte­g­ra­ted your hou­se having lia­bi­li­ty to make sure you are able to your blog websi­te!

  3. UFC 196 says:

    Than­ks for a marve­lous posting! I qui­te enjo­yed rea­ding it, you happen to be a great
    author. I will ensu­re that I boo­kma­rk your blog and will often come back down the road.
    I want to encou­ra­ge that you con­ti­nue your great work,
    have a nice mor­ning!

  1. 2009-12-28 ( Monday )

    […] it was not all that fun, and I had to use a number of resou­r­ces to get it wor­king. Many than­ks to Peng-Fei’s blog entry, whi­ch got me sta­r­ted, but didn’t qui­te take me over the fini­sh line. The Wor­dP­re­ss plu­gin […]

Leave a Reply

Your email address will not be published.

nine − six =

使用新浪微博登陆