If you are running WordPress on a VPS or dedicated server, a quick way to optimize performance is to install a php opcode cache. To understand why, you need to first understand how php processes a request.

A php request goes through the following steps:

  1. Read
  2. Parse
  3. Compile
  4. Execute
  5. Output

For every WordPress page requested, the php engine must go through all 5 steps. A php opcode cache keeps the complied php code in memory, thereby eliminating the 1st 3 steps above. Fortunately for you, installing and configuring a php opcode cache is simple. There are many php opcode caches, but my favorite is the alternative php cache (apc).

Here are the instructions for installing the alternative php cache (apc) on an ubuntu server:

1. Install php-apc

[sourcecode language=“bash”]apt-get update apt-get upgrade apt-get install php-apc[/sourcecode]

2. Configure php-apc by editing the apc.ini file

[sourcecode language=“bash”]vim /etc/php5/apache2/conf.d/apc.ini[/sourcecode] Add the following to the apc.ini file (where 20 the amount of RAM allocated to your apc cache. I’ll discuss how to find the size needed later): [sourcecode language=“bash”]apc.shm_size=20[/sourcecode]

3. Restart apache

[sourcecode language=“bash”]/etc/init.d/apache2 restart[/sourcecode]

4. Verify Status

To check the status of you apc opcode cache you can install a monitoring script from http://git.php.net/?p=pecl/caching/apc.git;a=blob_plain;f=apc.php;hb=HEAD by uploading the apc.php script to your web server. Use your web browser to browse to this script page and you will see a dashboard of the status of the apc opcode cache. One of the items you should pay attention to is the Cache full count. This tells you how many times that the apc opcode cache ran out of memory.  You should try to raise the amount of RAM you have allocated to apc to avoid this. On a server that I administer I have the cache set to 60, and this is enough to have WordPress (including plugins and themes) and phpMyAdmin in the apc opcode without ever running out of memory in the cache. If you have any questions, please leave a comment below.