WordPress is an amazingly powerful blog and website content management system. In fact, it is what we use. The only caveat is that it tends to be somewhat bloated and requires a bit of tweaking and custom solutions when the blog or website traffic increases. There have been countless times we have been browsing Digg or Reddit and a linked blog post or WordPress website is down because of the huge increase in traffic.

Our goal, is to provide five essential steps for keeping your WordPress blog and websites up. All of our steps relate specifically to server infrastructure, and don’t hit any of the other ways to optimize Wordprss itself with plugins or code modification; we’ll leave that to another blog post.

1lighttpd - fly light

Lighttpd Web Server Instead Of Apache

Lighttpd offers a small memory footprint compared to other web-servers, and superior performance when serving static content such as images, css, javascript and plain html files. In addition it has gained a large adoption rate and is used by several popular web 2.0 sites like YouTube, Wikipedia and Meebo. Server side requests such as PHP are passed off to fastCGI for processing. Lighttpd has a extensive library of plugins such as mod_rewrite, mod_redirect, mod_fastcgi, mod_expire, mod_compress, and mod_proxy.

Also, see our blog post (Lighttpd Web Server With WordPress Permalinks) on how to properly configure permalinks (mod_rewrite) on lighttpd for WordPress. It is a bit different than Apache.

2PHP: Hypertext Preprocessor

XCache PHP Caching

XCache is a fast, stable PHP opcode cacher that has been tried and tested. XCache accelerates the performance of PHP on servers. It optimizes performance by removing the compilation time of PHP scripts by caching the compiled state of PHP scripts into memory and uses the compiled version straight from the RAM. This will increase the rate of page generation time by up to 5 times as it also optimizes many other aspects of php scripts and reduces serverload. We have tried other PHP opcode cachers such as eaccelerator, iconCube, and APC, but have found that XCache delivers the best performance results, and also is the simplest to install and configure.

3GZip

Enable Gzip Compression Of Static Content

Gzip is a popular and effective compression method. Most modern web browsers support and accept compressed data transfers. By gziping static content such as css, javascript, and html files, response times can be reduced by 60-70%. There is a nice guide on how to configure Gzip on lighttpd at: http://www.cyberciti.biz/tips/lighttpd-mod_compress-gzip-compression-tutorial.html

4InnoDB

MySQL Storage Engine InnoDB

Change all WordPress MySQL tables to use InnoDB storage engine instead of MyISAM. InnoDB is transaction-safe meaning data-integrity is maintained throughout the entire query process. InnoDB also provides row level locking, as opposed to table-locking, meaning while one query is busy updating or inserting a row, another query can update a different row at the same time. These features increase multi-user concurrency and performance.

Here is a quick script to update all tables in a database to the InnoDB storage engine.

mysql -p -e "show tables in PUT-DATABASE-NAME-HERE;" | tail --lines=+2 | xargs -i echo "ALTER TABLE {} ENGINE=INNODB;" > alter_table.sql
mysql --database=PUT-DATABASE-NAME-HERE -p < alter_table.sql

5MySQL - The world's most popular open source database

Tune MySQL

This is perhaps the most difficult step, because there inst a cut and dry approach. Often times it requires a bit of trial and error, and tweaking various configuration directives. No need to fret though, we have listed a full MySQL configuration file below. The directives in this configuration file are optimized for MySQL5 running WordPress on InnoDB tables. Additionally, the configuration file below is for a dedicated MySQL5 server with at-least 256MB of dedicated memory and four processors.

OBLIGATORY WARNING…Please don’t blindly copy the MySQL configuration file below into your server and restart MySQL without first doing a full backup, and understanding the implications of these changes. The last thing we want, is people hosing their MySQL databases.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# @author 619Cloud <http://www.619cloud.com> <support@619cloud.com>
# @copyright (c) 2010 619Cloud. All Rights Reserved.
 
# Optimized for a dedicated MySQL5 server with at-least 256MB of dedicated
# memory, four CPUs, running InnoDB storage engine tables.
 
[mysqld]
skip-bdb
skip-ndbcluster
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-storage-engine=InnoDB
long_query_time=2
log-slow-queries=/var/log/mysql_slow.log
expire_logs_days=14
max_connections=50
external-locking
 
port=3306
net_retry_count=5
max_connect_errors=50
wait_timeout=3600
connect_timeout=15
 
open_files_limit=1536
key_buffer_size=64M
innodb_buffer_pool_size=128M
innodb_additional_mem_pool_size=8M
innodb_log_buffer_size=8M
group_concat_max_len=16k
max_sort_length=16k
max_length_for_sort_data=16k
query_cache_type=1
query_cache_limit=4M
query_cache_size=64M
innodb_thread_concurrency=16
thread_concurrency=16
thread_cache=128
thread_stack=1M
read_buffer_size=1M
join_buffer_size=2M
read_rnd_buffer_size=1M
table_cache=512
tmp_table_size=256M
max_heap_table_size=256M
innodb_log_file_size=128M
innodb_flush_log_at_trx_commit=1
innodb_file_per_table
log-warnings
 
user=mysql
old_passwords=1
 
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

If you have any additional questions, please leave comments below and we will reply.

Finally; want to let us professionally handle all the details and nitty gritty of keeping your WordPress blog or website up? Sure, no problem. We have a special wordpress solution based off two virtual private servers that has a discounted setup fee ($150) and does all the steps listed in this post, plus a plethora of additional tweaks and performance tricks guaranteed to keep your WordPress blog and website up and buzzing along.

» Read more about our WordPress hosting solution