How To Setup And Use Memcached With WordPress

A few days ago, I spoke about the architecture that powers Techie Buzz. In that post, I had mentioned that memcached was one of our key ingredients.

Memcache is a powerful tool to share objects across servers and it is used by several big sites including , Yahoo and many more. The best part about using memcached on your server is that you can cut down on your database queries significantly and store commonly used objects in memory and share it across multiple servers.

If you use WordPress on a multi-server setup, you can easily cut down on DB queries by up-to 50% by implementing memcached. If you are interested in knowing how to implement memcached on your server, here is a tutorial. The assumption is that you are using Ubuntu, if not, the installation steps might change.

How To Install Memcached And Configure It

Step 1: Install memcached using the command given below

sudo apt-get install memcached

Step 2: After you have installed memcached you will have to configure it through a .conf file, to do that use the command given below

vi /etc/memcached.conf

Step 3: In the configuration file you will find few parameters, you can ignore the -d, -u and logfile parameters and leave it as default. However, change the -m, -p and -i parameters to suit your servers. The -m parameter specifies the memory that will be allocated to memcache. The -p parameter specifies the port that memcached will run on and the -l (ell) parameter specifies the IP address the memcached server will run on. You will need to change the -l (ell) parameter value from to a local or global IP address of your server. This is necessary because your memcached server will be accessed by outside servers and using will not work then.

Once you have done that run the following command.

service memcached restart or /etc/init.d/memcached restart

Using Memcached With WordPress

Once you have setup your memcached server, it is time to now setup WordPress to use memcached to store your objects. To do that, head over to and install the memcached plugin for WordPress. Unlike other plugins, you will have to drop this file into the wp-content directory and not the plugins directory.

You will have to install additional plugins for your server to make use of this plugin, namely PECL memcache extension which can be downloaded from

Now comes the part where you will actually tell WordPress to use memcached as an object storing mechanism. To do that, open the wp-config file and add the line below to it.

global $memcached_servers;
$memcached_servers = array(‘default’ => array(‘memcache-server-ip-or-name:11211′));

The array is used to define multiple memcached servers which can be used for your site. Please make sure to edit the name/ip of the server and the port before you save the file.

That’s it. Now just refresh your cache and WordPress should start storing the objects in memcache and will access your database very sparsely.  Do let me know if you have any problems or difficulties in setting this up through your comments.

Bonus Note: You can browse and manage your memcache server through a WordPress plugin called WP Memcached Manager which can be downloaded at

Published by

Keith Dsouza

I am the editor-in-chief and owner of Techie Buzz. I love coding and have contributed to several open source projects in the past. You can know more about me and my projects by visiting my Personal Website.I am also a social networking enthusiast and can be found active on twitter, you can follow Keith on twitter @keithdsouza. You can click on my name to visit my Google+ profile.

  • Hi! Thank you for writing this post. It will help me a lot to install memcached. This is easily one of the most useful articles I’ve read this year and it is a great start of people would get a chance to read this.

    Great work!


  • sasikumars

    sir my photoshop is not intal what is thweprob

  • Pingback: Wordpress | Pearltrees()

  • Do any WP Plugins have to be rewritten in order to work with Memcache?

    • If they use the cache provided by WordPress they don’t need to change anything

  • osvy

    How do I install PECL memcache extension ?

    • @osvy – You can run the command “pecl install memcache” without the quotes to install the extension

  • Hey, thanx for the tutorial.

    Do you recommend any script that lets you to monitor Memcached performance (in GUI) ?

    (other than SSH – ./memcache-top-v0.6 )