We’ll do a complete tutorial in this blog series. Hopefully we can get this done in 3 main blog posts and then an accompanying post with some information about using Memcache in other common PHP scripts such as vBulletin, IPBoard, Joomla, etc.

Part 1 – Install Memcache

Part 2 – Install eAcclerator

Part 3 – Modify WordPress to use Memcache + eAccelerator

PART 1 of 3: Memcache
Memcache aka Memcached is:

...a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load

In layman’s terms, it’s a caching system using RAM to cache your website and make it run quicker. Why would Memcache speed up your site? It basically takes your often hit pages and caches it into RAM. By caching it into RAM, your page doesn’t need to be regenerated as the information is still in memory. Large websites have huge Memcache server farms whose sole purpose is to cache data for quick retrieval, that’s how the big boys do it. Even Howard Stern uses Memcache.

Well we might not have millions of hits and gigabytes of Memcache but even a little bit of Memcache can help medium traffic sites. No, memcache is not for everybody, it doesn’t do you much good if your site doesn’t see much traffic. But if you have a popular WordPress Blog or vBulletin forum, a little Memcache can go a long way.

We have found that Memcache + eAccelerator greatly increases the speed of your site and reduces the overall server load. So you might ask, how do I get Memcache working with WordPress, let’s get started:

NOTE: This article assumes that you have root/admin access to your server. If you are on a hosted/shared webserver, just ask your hosting company to do the work for you and skip to the WordPress Memcache plugin section.

1) First things first, your server must have memcache installed on it. These are CentOS/RHEL instructions, you’ll have to figure out how to do it for Debian/Ubuntu but it should be similar.

Download, Compile and Install Memcache (also installs zlib which is required by Memcache):
mkdir /usr/src/install
cd /usr/src/install
wget http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
tar xzvf memcached-1.2.2.tar.gz
cd memcached-1.2.2
yum -y install libevent-devel
./configure
make
make install

2) Install the Memcache PHP extension:
yum -y install zlib-devel
wget http://pecl.php.net/get/memcache-2.1.2.tgz
tar xzvf memcache-2.1.2.tgz
cd memcache-2.1.2

Ok, now you have to find where your “phpize” resides, be careful if you have multiple PHP versions, you have to find the right one:
locate phpize
This should output the location of phpize, you will need to insert it into the following step:

export PHP_PREFIX="PATH_TO_YOUR_PHPIZE_COMMAND"
$PHP_PREFIX ./configure --with-php-config=/hsphere/shared/php5/bin/php-config
make
make install

Now you have to edit php.ini to include Memcache, first locate the correct php.ini file. Again, it should be the main php.ini file:
locate php.ini

Once you have the path to php.ini, you need to edit it to include the Memcache extension
nano PATH_TO_PHP.INI_FILE

INSERT this in there and save your file:
extension=memcache.so

Restart your webserver and you should have Memcache working.