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.
#1 by Apollinaire on July 9th, 2008
Quote
Being a regular customer I do not have access to php.ini (or I am not able to find it). Putting it in the WP folder does not do the trick. Can you help me with the optimising? Thank you (if anyone reads this comment)
#2 by richard on February 18th, 2009
Quote
Where can i find part 2 and 3?
#3 by Bill Bartmann on September 1st, 2009
Quote
Cool site, love the info.
#4 by cenOTapH on September 28th, 2009
Quote
I already have the two waiting for optimization part for wp
#5 by JimmyBean on October 1st, 2009
Quote
I don’t know If I said it already but …This blog rocks! I gotta say, that I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks,
A definite great read..Jim Bean
#6 by Nasir on March 29th, 2010
Quote
What i do not understand is why should both be enabled, both seem to do the same thing? Why should this optimize more. Do you have any test results?