Installing WP Super Cache

From DreamHost
Jump to: navigation, search

Contents

Why Install WP Super Cache?

The WordPress blogging software is one of the most popular in use right now. It's a great piece of software and work well. Unfortunately, in its out-of-the-box state it isn't very efficient. Whenever someone views a page it has to be processed by PHP and then served via Apache. These can consume vast amounts of memory if your site gets even a moderate traffic spike. If one of your posts gets slashdot'd or on Digg, well, let's just say things won't be pretty.

WP Super Cache helps solve this problem. When one of your pages is viewed, it's parsed by PHP and then the output is saved (or cached) by WP Super Cache in a static file. The next time that page is viewed, the static file is served directly through Apache, bypassing the need to parse it via PHP and thus saving vast amounts of memory. This will both help your site survive large traffic spikes and help it to behave nicely in DreamHost's shared hosting environment. To get a better idea of how this all works, you can take a look at the WordPress Optimization page.

Configuring WordPress Permalinks

Before you actually start installing WP Super Cache, you need to enable permalinks for your WordPress blog. Go to your admin panel and go to the Settings -> Permalinks area. Any of the options aside from "Default" should work, so your settings should look something like this:


Wpsc permalinks.jpg


Installing WP Super Cache

You can download the WP Super Cache plugin here. There are also additional installation instructions available here that you'll likely want to read over and be familiar with. If you've never installed a WordPress plugin before, you'll likely want to look over the Managing Plugins WordPress page. Before continuing, you should note that WP Super Cache is NOT compatible with WP Cache. WP Cache is an older caching plugin that doesn't work as well. You'll want to completely remove that plugin from the wp-content/plugins/ folder before installing WP Super Cache. You'll also want to edit your wp-config.php and make sure the WP_CACHE define is deleted, and remove the files wp-content/wp-cache-config.php and wp-content/advanced-cache.php. These will be recreated when you install and activate WP Super Cache. Once you've done that, just download the plugin from the address above and upload it to your wp-content/plugins/ folder.

Activating WP Super Cache

Once you've installed WP Super Cache, you'll need to activate it which involves a few more steps than most plugins. First, you activate it from the Plugins area of your admin panel. When you've done that, you should see something like this:


Wpsc activate super cache.jpg


As you can see above, WP Super Cache is disabled by default. Go ahead and click on the "plugin admin page" link at the top of the page to get to the WP Super Cache configuration page. From there, you'll want to adjust your settings to look something like the below:


Wpsc enable super cache.jpg


Verifying WP Super Cache is Actually Working

At this point in time, it can appear as though everything has been configured correctly, but WP Super Cache could still not be functioning. Assuming your blog is running on a domain named "example.com", you can verify this by checking to see that you have a .htaccess file located at /home/username/example.com/.htaccess with the following content:

# BEGIN wp-super-cache
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_METHOD} !=POST
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 %{REQUEST_METHOD} !=POST
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]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END wp-super-cache

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


Then check to make sure you have a .htaccess file located at /home/username/example.com/wp-content/cache/.htaccess with the following contents:

# BEGIN supercache
<IfModule mod_mime.c>
  AddEncoding gzip .gz
  AddType text/html .gz
</IfModule>
<IfModule mod_deflate.c>
  SetEnvIfNoCase Request_URI \.gz$ no-gzip
</IfModule>
<IfModule mod_headers.c>
  Header set Cache-Control 'max-age=300, must-revalidate'
</IfModule>
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html A300
</IfModule>

# END supercache

At this point, the best way to confirm your caching is working correctly is to run some high traffic simulations on your domain. You can get information on how to do this in the Simulating High Traffic section of the PS Optimization wiki article. You can also get some good information on what you should expect to see in the WordPress Optimization wiki article. Essentially, under high traffic you shouldn't see "php5.cgi" processes spawning for your user when using the top -c command while logged in via SSH.

If it still isn't working, you might need to deactivate WP Super Cache and remove the files mentioned in the Installing WP Super Cache section above again. You might also need to clear out the files and folders stored in the wp-content/cache/ folder. Once you do that, reactivate WP Super Cache and then confirm the .htaccess files are in place. Then check to see if you're still having php5.cgi processes spawning or not. If you keep having trouble getting it to work, you can contact DreamHost tech support and they might be able to help you (though technically this sort of thing isn't officially supported, they might be able to assist you). If not, you can check the WP Super Cache forum or the WordPress support forum.

Performance Notes

WP-Supercache supports two modes:

  • PHP Mode
  • Mod_rewrite Mode

There are pros and cons to each, however in terms of performance, if you're content is not going to change that often, you will likely want to use Mod_rewrite mode, as it will speed up the TTFB (Time to first byte) by orders of magnitude. This is because it doesn't have to search for additional PHP handlers to parse the cached file. Instead, it writes the content as raw HTML, and serves the HTML by itself.

See Also

Personal tools