Jump to Navigation

Speed up your WordPress Blog!

Well, making your blog really fast is quite a nice thing for your visitors. And lately it’ll even fall under SEO, as Google now takes Page Speed into account for ranking your website. So how do you get your freshly installed wordpress site really fast? It’s actually really easy.

First, you will need a PHP accelerator, which caches precompiled PHP Opcode, so it’ll run much faster. PHP is a script language, so it takes really long to parse and interpret you PHP code, a Opcode cache would simply skip this time. You will need a dedicated or at least virtual server with root access to do this. I’ll show you how to install APC, as it is really easy to install and use on Debian Lenny. So to install APC, simply run the following command as root:

aptitude install php-apc

Afterwars, edit the /etc/php5/conf.d/apc.ini and replace it with the following:

extension=apc.so
[apc]
apc.enabled = 1
apc.shm_size = 64
apc.ttl = 7200
apc.user_ttl = 7200
apc.mmap_file_mask = /tmp/apc.XXXXXX

Now restart Apache with /etc/init.d/apache2 restart and APC is up and running.

Next you will need to setup mod_expires to configure client side caches. mod_expires is usually already installed when you use apache2, so you will only need to enable it via a2enmod expires. After that, find the default vhost configuration file (usually /etc/apache2/conf.d/default-config) and add the following lines:

ExpiresActive On
ExpiresDefault "access plus 300 seconds"
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/javascript "access plus 1 day"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 day"

Now restart Apache again with /etc/init.d/apache2 restart and client side caching is ready to go.

The next step is installing a WordPress caching plugin with APC support, like W3 Total Cache and setting up Page, Minify and Database Caching with Opcode APC, which is so easy I don’t even need to explain it any further.

There is one optional step, which helps improve page loading time on site with a lot of static content (like images). As connections are limited per hostname, having a lot of images will cause the site to load really slow, as the browser has to wait until the current images have finished loading before it can load new ones. To solve this problem, simply create multiple ServerAlias in your virtual-host file and serve your static content from them. It is strongly recommended that you use a hostname wrapper in this case, which generates the same Alias for each file. You certainly don’t want a user to start loading the same file from different hostnames, as that would actually slow down the page speed. There are several ways to solve this problem. I created a function that calculates a number from the filename and use that as a subdomain where the file is being loaded from.

With this steps, page loading time dropped from 10-20s to 1-2s on my web projects (Full page load with images and scripts). It feels really nice to see the page load up so fast.

4 Responses to “Speed up your WordPress Blog!”

  1. Dirk:

    Hallo,
    qTranslate ist ein großartiges Plugin. Leider ist der Wechsel zwischen den Sprachen mit qTranslate in meinem Blog nicht mehr möglich, seitdem ich W3 Total Cache installiert habe. Nur mit ausgeschaltetem Page-Caching können beide koexistieren :(

  2. Ryan:

    Any chance that qTranslate and W3 Total Cache will start working together?

  3. Qian Qin:

    You will have to use Super Cache as W3 isn’t supporting any other plugins yet.

  4. Thomas:

    Will qTranslate support WordPress v.3 ?