Thoughts on Medicine, Anesthesiology, and Software header image 2

How to Install WP-SuperCache on Pair

October 12th, 2008 by Patrick

Recently Matt Cutts discussed difficulties he had with WP-SuperCache on his Pair Networks hosting account. I use PairLite, which is hosting from the same company with less support and no SLA. I love Pair because they provide shell access to FreeBSD and an Apache webserver.

The problem Matt runs into is that WP-SuperCache, like many WordPress addons, assumes that it has write access to the blog directory. This assumption makes WordPress very easy to configure for users, but weakens security and has led to various security holes in the past.

I set up my WP install with no group or anyuser write permission (0705 for you Unix types.) This disables the ability for me to edit the configuration, themes, and plugins from a web browser, but I can handle that. Only wp-content/uploads has write permission, for images.

So, how to install WP-SuperCache from a FreeBSD shell? Here’s the step-by-step:

  • Download and unzip it to wp-content/plugins/wp-super-cache.
  • Change your current directory to “wp-content”.
  • Type: ln -s plugins/wp-super-cache/wp-cache-phase1.php advanced-cache.php
  • Type: cp plugins/wp-super-cache/wp-cache-config-sample.php wp-cache-config.php
  • If you want to allow WP-SuperCache to edit the config for you, type: chmod 777 wp-cache-config.php.
  • Create the cache directory: mkdir cache
  • Set the cache permissions: chmod 777 cache
  • Create cache/.htaccess with these contents:
# BEGIN supercache
<IfModule mod_mime.c>
  AddEncoding gzip .gz
  AddType text/html .gz
<IfModule mod_deflate.c>
  SetEnvIfNoCase Request_URI \.gz$ no-gzip
<IfModule mod_headers.c>
  Header set Cache-Control 'max-age=300, must-revalidate'
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html A300
# END supercache
  • Update your blog’s .htaccess file with these additional lines (the RewriteRules for fancy post links should already be in place):
# for supercache
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{QUERY_STRING} !.*attachment_id=.*
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
#end supercache

Once the above steps are done, you should be able to activate the plugin and go to the Options screen to turn on WP-SuperCache. That’s it, it should just work.

If you want to wipe the cache directory, you will find you cannot do so from the shell since the cache files are created by the cache. So, make WP wipe it for you. Go to Options, choose Super Cache Compression Enabled, hit Update, then Super Cache Compression Disabled, hit Update, and the cache will be clean. UPDATE: Just noticed the “Delete Cache” option on the top bar of the admin screens. That should do the job easily.

Let me know if this works for you in the comments.

Tags:   · · · No Comments

Leave a Comment

0 responses so far ↓

There are no comments yet...Kick things off by filling out the form below.