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:
- Download WP-Cache zip file (current version as of writing is 2.0.17) and unzip into wp-content/plugins folder.
- 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. - 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).
- Open the standard wp-config.php file and add
define('WP_CACHE', true); - 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. - 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)) { { - Finally, open wp-content/plugins/wp-cache/wp-cache-phase2.php and search for
ob_end_clean();and replace withob_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. - That’s it- you’re done. Now goto Options/WP-Cache and turn caching on.
March 2nd, 2006 at 1:22 pm
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!
March 3rd, 2006 at 12:39 pm
Don’t think flush() after ob_end_clean() would work (and doesn’t on Windows)- once ob_end_clean() is used, the buffer’s already empty (check PHP docs).
Cheers,
Andi
March 20th, 2006 at 11:27 pm
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?
March 21st, 2006 at 4:09 pm
Tim,
not sure what you mean by ‘Cache Contents still equals 0′. The solution described should work on IIS and Apache both, tested on Apache.
Andi
March 21st, 2006 at 8:36 pm
In WP Admin, under Options > WP-Cache:
It says:
WP-Cache Manager
Cache contents
0 cached pages
0 expired pages
April 17th, 2006 at 9:04 pm
I’m having the same problem as above. Everything seems to be running fine, cache files are being written to the cache directory, and there’s a dynamic page served comment at the end of every page. The only problem is, none of the cache files are being used (0 cached pages, 0 expired pages), and it’s regenerating a new page every time.
April 18th, 2006 at 11:11 am
Did you remember to add the define to wp-config.php?
June 5th, 2006 at 5:10 pm
Mate, that’s a sweet How-To. Thanks.
June 5th, 2006 at 6:36 pm
You’re welcome!
September 30th, 2006 at 8:55 pm
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?
October 3rd, 2006 at 7:05 am
[...] Digital Bites [...]
October 16th, 2006 at 2:17 am
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!
October 16th, 2006 at 2:21 am
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 -->
November 1st, 2006 at 4:45 pm
Awesome job man. It took about 20-25 minutes to set up but its better then spending hours switching servers. Thank you.
November 7th, 2006 at 1:24 pm
This is for Apache on Windows and does not work for IIS 6 on Windows Server 2003.
I just checked both and can verify that.
November 7th, 2006 at 10:23 pm
[...] 不过,WP-cache基于Linux/Appache开发,在Windows/IIS平台下并不能按其默认的方法安装,因为其中有些针对Linux/Appache的环境设定。通过Google找到了这篇介绍在Windows中安装WP-cache的文章,依其步骤,果然能够使用WP-cache了。 [...]
November 10th, 2006 at 12:17 pm
[...] After writing the tutorial on how to get WP-Cache running on Windows, I’ve realized I could just make it a bit easier. Together with the latest WP-Cache release 2.0.19, I’ve build a preconfigured package. [...]
March 16th, 2007 at 3:07 pm
Regarding comment by Computer Guru- the solution for IIS has been added as step 2).
Andreas
March 16th, 2007 at 3:23 pm
[...] written in this post, WP-Cache needs several modifications in order to run on Windows and/or IIS. Provided below is an [...]
April 21st, 2007 at 5:28 pm
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?
April 21st, 2007 at 6:13 pm
Sorry,
Actually, I don’t think it’s reading the meta information.
April 23rd, 2007 at 8:57 am
Not sure what you mean with meta pages/ information? What platform are you running on?
April 25th, 2007 at 11:41 pm
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
May 4th, 2007 at 1:09 am
Any word on help?
May 17th, 2007 at 7:37 pm
I would really appreciate any help or advice on the problem I listed above.
May 24th, 2007 at 3:20 pm
Hi,
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,
-SB
May 24th, 2007 at 4:56 pm
Just rename the file to wp-config.php. Reason is simply that when installing a new WP-Cache version, it won’t override your custom wp-config.php.
Cheers,
Andi
May 24th, 2007 at 5:45 pm
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,
SB
June 6th, 2007 at 3:46 am
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
June 7th, 2007 at 4:09 am
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…
September 25th, 2007 at 7:15 pm
[...] Digital Bites [...]
October 9th, 2007 at 9:23 am
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?
Thanks
May 17th, 2008 at 12:18 am
[...] wp-cache wordpress plugin on IIS windows server http://www.cpuidle.de/blog/?p=30 http://www.village-idiot.org/archives/2007/07/01/wp-cache-symbolic-link/ http://aralbalkan.com/1133 [...]
June 16th, 2008 at 4:41 pm
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.
September 11th, 2008 at 10:49 pm
Thanks for this how-to. It was really helpful to get my wp-cache working on windows.
October 17th, 2008 at 5:59 pm
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????
November 4th, 2008 at 6:57 pm
[...] 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 [...]