Tuts Tuesday: Optimizing Your WordPress Site Part 1

Unless you have been living under a rock, it’s official that Google counts a website speed as a ranking factor in the search engine. Now, how can we optimize our WordPress site to run as fast as it possibly can and reach its maximum performance?

Through this two part series article, we will guide you on how to tweak your WordPress configuration to get some significant performance.

I suggest you benchmark your current website performance before diving into the process to compare the improvements you have made. You may use any of the website speed and performance check tools.

Let’s begin!

Optimizing WordPress Site

  1. Server optimization – covers the optimization on Apache HTTP server, MySQL, and PHP.
  2. Site optimization – covers the optimization on WordPress and its plugins.

This article will cover the first part, the server optimization. This is best for those who have VPS (virtual private server) or a dedicated server that you can have access on the configuration of the necessary applications.

Apache HTTP Server

There are lots of websites that talks about optimization of Apache HTTP server. To summarize, the following are the recommended directives:

Trim Down Unnecessary Modules

By default, there are lot of modules that are active. Most of the modules are not useful at this point so in order to save resources, we have to trim it down by commenting the unnecessary modules except the following:

LoadModule authz_host_module modules/mod_authz_host.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so

Setting MaxClients

The MaxClients directive sets the number total concurrent connections. Setting values may vary depending on the capacity of RAM. Thus there is an article stating the formula:

MaxClients = 150 × RAM Capacity (in Gigabytes)

For example, if your server has 2GB RAM, you can set the value to 300. But if your server has only 512MB of RAM, set the value to 75.

Setting ServerLimit

The ServerLimit directive sets the maximum number of processes. The value should be the same as setting the MaxClients. The hard limit for MaxSpareServers is 20000 to avoid serious trouble due to primarily… typographical errors.

Setting MinSpareServers and MaxSpareServers

The SpareServers set the desired number of idle child processes. The recommended values are the following:

MinSpareServers 5
MaxSpareServers 10

Setting KeepAlive

The KeepAlive directive allows persistent HTTP connections. In theory, this will save significant latency time between connections, but this will create more resources.

If possible you should set the value of KeepAlive to off.

KeepAlive off

But if your site has lot of images and Javascript files, you may keep the value to on. But, you have to adjust the value of the following directives.

  • KeepAliveTimeout
  • MaxKeepAliveRequests

The KeepAliveTimeout sets the number of seconds of having persistent HTTP connections. The value should be low enough. Too high value will cause resource problems.

KeepAliveTimeout 5

The MaxKeepAliveRequests sets the maxiumum number of persistent requests in every connection.

MaxKeepAliveRequests 200

Setting StartServers

The StartServer directive sets the number of child processes upon startup. If your website receives low traffic, you can set the value to say, five (5). But if your website receives heavy traffic, it is best advised to set the value close to MaxClients.

StartServers 5

Setting Timeout

This directive sets the number of seconds will wait during processing before it fails. This also helpful to mitigate denial-of-service attacks. Set the value low enough not to complete the process before it loses connection.

Timeout 60

Save and Restart

So far, these are the recommended values for the Apache HTTP server configuration. You can tweak it as long as it won’t give problems.

MySQL

Below are the recommended values in the configuration of MySQL server.

[mysqld]
local-infile=0
key_buffer = 64M
sort_buffer = 1M
join_buffer = 1M
max_allowed_packet = 8M
max_heap_table_size = 16M
table_cache = 1024
sort_buffer_size = 8M
read_buffer_size = 1M
read_rnd_buffer_size = 768K
myisam_sort_buffer_size = 48M
thread_cache_size = 512
query_cache_type = 1
query_cache_limit = 4M
query_cache_size = 64M
tmp_table_size = 16M
thread_concurrency = 4
max_write_lock_count = 1
low_priority_updates = 1
 
[isamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M
 
[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

Afterwards, save your configuration and restart the MySQL server.

PHP

The PHP is an interpreted language and builds an opcode on the fly when the HTTP server requests the script. In order to increase performance, the PHP compiler cache saves the compiled state to the memory which allows the PHP engine to execute the script without building the opcode again.

There are PHP compiler cache available for your installation.

  • eAccelerator
  • APC
  • xCache

A warning though, the PHP compiler cache does not work with suPHP.

Up Next

Stay tuned for the second part of this Optimizing your WordPress site series. I will discuss about the general optimization of WordPress using plugins.

Categories: Tutorials, Tuts Tuesday

Tags: ,

Comments

  1. Brad Dalton 08.20.2012 Reply

    Good tut for the DIY inclined.

    If you can’t be bothered with all that, move to a fully managed server which is run by WordPress experts who focus on speed.

Add a Comment