Installing WP-Cache on Windows

WP-Cache is probably the most widely used caching plugin for WordPress. Unfortunately, it doesn’t support windows and numerous people failed with the installation. This article describes how to run WP-Cache on Windows.

Update: If you’re not interested in the individual configuration steps, you can just download a pre-built version here.

To install WP-Cache on Windows, follow the following steps:

  1. Download WP-Cache zip file (current version as of writing is 2.0.17) and unzip into wp-content/plugins folder.
  2. If you’re planning to run WP-Cache on IIS, you’ll first need to update wp-cache-phase1.php. Problem is that IIS apparently doesn’t set the REQUEST_URI server variable as expected. To fix this issue, replace $_SERVER[’REQUEST_URI’] with $_SERVER[’SCRIPT_NAME’].$_SERVER[’PATH_INFO’]. This step was contributed by Unsought Input.
  3. Copy wp-content/plugins/wp-cache/wp-cache-phase1.php to wp-content/advanced-cache.php (not really sure why this isn’t simplified by the author).
  4. Open the standard wp-config.php file and add define('WP_CACHE', true);
  5. Now comes the tricky part:
    open wp-content/plugins/wp-cache/wp-cache.php in your favourite text editor. Search for the wp_cache_add_pages function and change the function code like this:
    add_options_page('WP-Cache Manager', 'WP-Cache', 5, 'wp_cache/wp_cache.php', 'wp_cache_manager');
    Reason the original code doesn’ work is that the original __FILE__ resolves to wp_cache\wp_cache.php which some browser eat and convert to wp_cachewp_cache.php- which doesn’t exist.
  6. Second problem is that WP-Cache checks for installation step 2) in a windows-incompatible manner. Search for the wp_cache_check_link function. Change the first three lines after the variable declaration in this way:
    # if ( basename(@readlink($wp_cache_link)) != basename($wp_cache_file)) {
    # @unlink($wp_cache_link);
    # if (!@symlink ($wp_cache_file, $wp_cache_link)) {
    if (!file_exists($wp_cache_link)) { {
  7. Finally, open wp-content/plugins/wp-cache/wp-cache-phase2.php and search for ob_end_clean(); and replace with ob_end_flush();. Without this change the cached page contents are not written back when the page is initially cached. It’s unclear to me if that works under *nix, I assume it couldn’t.
  8. That’s it- you’re done. Now goto Options/WP-Cache and turn caching on.

26 Responses to “Installing WP-Cache on Windows”

  1. Joao Says:

    regarding ob_end_clean(); i see can see a call to ‘flush();’ just a few lines bellow, but i’m not sure exactly how this works…

    anyway, nice and simple howto, thanks!

  2. Tim Says:

    First, when you say Windows, do you mean IIS? Also, I tried this solution, but I’m not sure if it’s working. I activated the plugin, and enabled it via Options > WP-Cache, but Cache Contents still equals 0. Is that correct?

  3. Tim Says:

    In WP Admin, under Options > WP-Cache:

    It says:

    WP-Cache Manager

    Cache contents

    0 cached pages

    0 expired pages

  4. Tom Says:

    Mate, that’s a sweet How-To. Thanks.

  5. Joe Says:

    Excellent write-up. I especially like that you fixed the symlink function with windows-compatible code (I just return true on the whole function :-)).

    However, I’m having the same problem as Tim and Adan: pages are accumulating in the cache folder, but the browser keeps getting regenerated content for the cached pages. I can see this using Fiddler.

    The wp-cache admin screen says 0 files cached.

    I noticed that the response header for the intended page has:

    Cache-Control: no-cache, must-revalidate, max-age=0
    Pragma: no-cache

    Doesn’t this mean that the browser should never cache the content? If so, what could be setting this?

  6. Thanks WP-Cache!!! « Jayant Kumar Gandhi Says:

    […] Digital Bites […]

  7. Scott Carpenter Says:

    Great instructions — thanks. Seems to be working fine, although I’m wondering about individual post pages.

    For the main page and “page” pages (about, site-map, etc.), the pages go in to the cache folder, they register in the admin options in the “cached pages” count. (Also, each of the html pages in the cache is accompanied by a .meta file.)

    For these pages, I see this in the source at the bottom of each page:

    For individual posts, the cached page is created, but there is no .meta file and it isn’t counted in the admin page. When I load one of these pages, it doesn’t appear to regenerate the cache html, but all I see in the source is:

    So how can I tell if I’m using the cached version?

    I tried changing the file in the cache and loading it, but didn’t see that file when loading the page.

    And after all that, I decided to go for it and install on my non-Windows host, and everything seems to work fine there with the basic WP Cache installation. I’m going to go ahead and post this out of curiosity if someone else has seen the same thing and has an answer — it doesn’t really matter if the cache works on my local Windows test environment but I’d like to keep the two in sync as much as possible.

    Thanks again for your help!

  8. Scott Carpenter Says:

    Crud, forgot to encode the < and >

    Let’s hope the <code> tag works…

    The working pages:

    <!-- Dynamic Page Served (once) in 0.334 seconds -->
    <!-- Cached page served by WP-Cache -->

    Non-working pages:

    <!-- Dynamic Page Served (once) in 0.334 seconds -->

  9. IIS中启用WP-cache提高访问速度 | SEO探索 Says:

    […]   不过,WP-cache基于Linux/Appache开发,在Windows/IIS平台下并不能按其默认的方法安装,因为其中有些针对Linux/Appache的环境设定。通过Google找到了这篇介绍在Windows中安装WP-cache的文章,依其步骤,果然能够使用WP-cache了。 […]

  10. Nick Says:

    I have installed your WP-Cache 2.1.0 on Windows plugin. I am still have a problem. Under the options > wp-cache page I still get:
    0 cached pages
    0 expired pages

    I have added the define to wp-config.php

    I’ve narrowed the problem to the following: http cached pages are being written to the cache folder, but meta files are not.

    Can you please help?

  11. Nick Says:

    Actually, I don’t think it’s reading the meta information.

  12. Nick Says:

    We have a Windows 2003 IIS 6 Server. It is caching the pages, but it is not grabbing the cached pages, when the page is accessed. It is simply caching it each time. We’re using PHP 5.2.0

  13. Nick Says:

    Any word on help?

  14. Nick Says:

    I would really appreciate any help or advice on the problem I listed above.

  15. SB Says:

    I’m trying to fix the install for this plugin but I had to create the advance-cache.php file and now I realize that I do not have a wp-config file. Should I create this one? I only have a wp-cache-config-sample.php file.

    Is this normal?

    Is there another plugin to download that has the files needed?

    Thanks for any help,

  16. SB Says:

    I found the config file. The “symbolic link”, is that what I created when I copied phase1 into the advance-cache file?

    Either way I’ve copied everything as directed above & this plugin seems to be more of a problem than a helper for my blog. I’ll just deactivate it and uninstall until something else comes along where I don’t have to mess with the code so much. I’m real new to WordPress. This is a lot to mess with for now

    -Thanks anyway,

  17. Mr. Fanrastic Says:

    It appears that wp-cache 2.1.1 is now using ob_end_flush(); instead of ob_end_clean(); in wp-cache-phase2.php.

    Thanks for the great tutorial! It’s working for me on WP 2.2 :)

  18. Says:

    WP-Cache up and running on IIS!…

    I finally got around to converting wp-cache to work with IIS. Thanks to CpuIdle’s blog for the excellent tutorial, and Yonatanz for his helpful post on Unsought Input that put it over the top!
    I’ll list out all the steps together here since Yonatan…

  19. the fly on the net » Installare WP-Cache su Windows e IIS Says:

    […] Digital Bites […]

  20. peter Says:

    Still get this error when I try to enable the plugin:

    Fatal error: Cannot redeclare wp_cache_add_pages() (previously declared in E:\resedagbok\wp-content\plugins\wp-cache\wp-cache.php:182) in E:\resedagbok\wp-content\plugins\wp-cache\wp-cache.php on line 183

    I have tried with both the pre built files and original files which I manually edited, still get that error.
    Running Win2003, IIS 6.0, PHP 5.2.3 and WordPress 2.3

    Any ideas?


  21. wp-cache problems with softlink (ln -s) - wordpress solution with ssh or virtualmin » SERPland Says:

    […] wp-cache wordpress plugin on IIS windows server […]

  22. Tommy Says:

    I tried every other unsuccessful method to get caching to work before I found this godsend. It is much appreciated. Now I just have to remember what to change back when I port my windows test version to the live unix server. Grrr … damned platform dependencies.

  23. Vishal Gupta Says:

    Thanks for this how-to. It was really helpful to get my wp-cache working on windows.

  24. Tomtep Says:

    I have same problem:
    0 cached pages

    0 expired pages
    In the page source:
    I think wp-cache never work!! for me.
    Any body help me????

  25. Expression » Blog Archive » EasyCGI Migration + Cogen Issues Says:

    […] get it working on an IIS environment, but there are a few good tutorials out there for it.  I used this one.  Well, the addon works great for cached pages, but anything that needed to be built was still […]

Leave a Reply