Integrating memcached to wordpress

by Ruchira on October 4, 2010

If you have busy site which gets thousands of visitors a day you might be having a hard time managing your server load. If you are using apache it makes it harder. The best decision is moving to nginx or lighttpd. If Im the one who manage the server Ill choose Nginx because its little bit ahead of lighttpd.

  • If you are newbie for nginx read my guide for installing nginx with all the necessary packages-

Nginx beats apache in all aspects. Some people using Nginx as reverse proxy to apache its good solution but all the dynamic php content is handled by apache. This 2010 and most of the sites are dynamic !

this is 2010

  • Now lets get to the topic

This is guide for using memcached with wordpress but this guide doesn’t cover how to install memcached ill explain that later! or please search google about installing memcached for your desired linux OS version.

So I’m assuming that you have installed Memcached with PHP memcached module,

  • There are 2 popular wordpress plugins for use with memcached!
  1. WP Memcached Manager ( For viewing memcached data without log in to SSH)
  2. W3 Total Cache ( Must need for integration)

“WP Memcached Manager” is not necessary but it can be used to view some useful information about work of your memcached deamon. here is a screenshot of wp memcached manager installed on my blog-

wp memcached manager

You can install both of those plugins normally just use automatic plugin installer which is built in to wordpress!

And check your memcached deamon is running with wp memcached manager! Its very easy to configure wp memcached manager you just need to enter the ip and the port of your memcached deamon.

So if its running you need to disable any other caching plugins like WP-SuperCache and HyperCache which you used previously.

  • Note- WP-Supercache is the best plugin out there for wordpress caching but unfortunately WP-Super cache only provide few options to work with memcached and it will not work correctly for most of the blog which use memcached

Then you need to configure W3-TotalCache to communicate with memcached deamon so w4 total cache will start storing your cached objects in memcached instance instead of disk.

Go to W3 total cache config page and run a compatibility check to ensure all the things are ok.
memcached compatibility

  • W3 Total Cache will detect if you have installed memcached and then you only need to configure the option “Memcached” from check boxes.

total cache memcached

So memcached will be used from now to cache your website. You can load your web site and view source to see its work!

using memcached

Performance comparison Later! :)

I'm Ruchira Sahan and all posts on this blog are completely my thoughts and writings. I love DIY and Technology. So feel free to contact me for anything about this blog and don't forget to add a comment if this blog helped you! Thanks
View all posts by Ruchira

Last 5 posts by Ruchira

  • Brandy Watcerson

    It is certainly interesting for me to read the blog. Thanks for it. I like such themes and everything connected to this matter. I definitely want to read more on this blog soon. BTW, rather good design that site has, but how about changing it every few months? I mean it :)

  • Dudeist

    Hi Ruchira!

    I’m really starting to like your blog. I’ve been here for an hour and thus far it’s given me a load of useful info and insight. I’ve followed your nginx auto-installer successfully (without any hiccups) and would like to know how you went about installing memcached on this stack, preferably a painless approach . You see, I’m a noob and can google too :) , but this is something I’d like to know from you, if possible.

    Also, in regards to the nginx auto-installer, would it be possible for the next release to include a www to non-www redirect option? I’ve made the changes already, but thought it might be more helpful to others.

    Thanks again, if you put some ads up I’ll be sure to click it.

    • Ruchira

      Thanks for your response :)
      And its very east to install memcached to lnmp because php module is built in to installer.
      If you are using debian or ubuntu just run,
      apt-get install memcached

      if you are centos run,
      yum install memcached

      And memcached will be automatically installed and start on 11211 default port! :)

      • Dudeist

        Well, this couldn’t be any easier. I’m really ashamed of my own ignorance…

        Thanks again.

        • Ruchira

          success? :)

  • bagus

    do I have to uncheck the browser cache option for w3 total cache? it seems if that option is enabled it ask for htaccess configuration

    • bagus

      When I do compatibility check I got “Opcode cache: Not installed ” is this a problem?

      • Ruchira

        no isnt a problem! You can install eaccelerator with just one command in LNMP ./ :)

    • Ruchira

      I have it unchecked :)

  • Damir-ElggFactory


    In Memcached Manager when adding server I see you have but what port should I use ?

    I can verify memcache is loade in phpinfo but in w3totalcache in my WordPress when I select memcached it says “Page caching is not working properly. Memcached server(s): may not running or not responding.”

    When I ran this in shell:
    telnet 11211 —-> “Unable to connect to remote host: Connection refused.

    so port is blocked?… what do I do?

    • Ruchira

      how did you installed memcached and whats your OS?

  • Damir-ElggFactory

    I believe it was enabled automatically (using your script)
    if not I probably used apt-get install (this is on Debian 5)

    In your image of Memcached Manager, I see ip but what port should I use?

    • Ruchira

      Memcached is not enabled automatically in LNMP but php extension for memcached enabled. So installing memcached become easy. Just issue the command

       apt-get install memcached

      and you will be good to go if you are not using any third party firewalls installed.

      If you got error let me know!

      • Damir-ElggFactory

        Ok I got an error:

        …following packages have unmet dependencies:
        libpcre3-dev: Depends: libpcre3 but 7.8-3 is to be installed
        E:Unmet dependencies. Try ‘apt-get -f install’ with no packages

        • Ruchira

          add these to your /etc/apt/sources.list file!

          deb lenny main
          deb lenny/updates main
          deb lenny/volatile main contrib non-free
          deb lenny main

          And after restarting VPS try again! And if you can try normal installation too. search google about how to install memcached on debian!

  • Damir-ElggFactory

    the same error ;-(
    should I try “apt-get -f install ” like it’s suggesting?

    what is -f going to do?

    do I need to run update?


    • Ruchira

      Try this

      tar xzf memcached-1.4.5.tar.gz
      cd memcached-1.4.5
      ./configure && make && sudo make install
  • Damir-ElggFactory

    got that done and it seems it installed (how to check?)
    I restarted the VPS as well.

    But I still get error in W3Totalcache “Memcached server(s): may not running or not responding.”

    • Ruchira

      try memcached start to see whether it starts or not! Also you can use wp-memcached manager plugin to see if memcached is running on that port!

      • Damir-ElggFactory

        That’s what I asked you earlier, what port and ip I need to use in wp-memcached manager for the server?

        • Ruchira

          default port is 11211 if you didnt changed it!

  • Damir-ElggFactory

    I got it started by :
    sudo memcached -d -u www-data -p 11211 -m 128

    as you see I’m giving it 128MB to use . Is that too much? it’s on 256MB VPS (512 burst) and now my ram used has doubled in “top” command. Is 128 MB too much to give to memcached according to my VPS specs?

    • Ruchira

      yes 128MB for 256MB is high! Im giving it 128MB because i have 512MB. You can give it 64MB but it can be not enough fi you have huge database and many objects to store on memcached!

  • Damir-ElggFactory


    couple of more questions
    in my wp memcached manager two fields named :
    GET HITS (33%)
    GET MISSES (67%)
    in your image get hits is 100% and get misses is 0?
    what does that mean? misconfiguration?

    and now my memory usage has doubled , is normal?

    Thanks a bunch.

    • Ruchira

      for about first 24 or 48 hours you will get some cache misses depending on your objects. But after about 48hours if you are getting more than 20% misses that means your assigned ram to memcached is low and you need to increase it. What is the size of your database? and how many posts do you have on your blog?

      Also memory usage will increase because memcached will take its assigned ram. use top command to see it.

  • Damir-ElggFactory

    Databases are small ( 3 and 7 MB), not very many posts.
    Actually I had to go back to using disc in W3 total cache as it slowed down the page loads for some reason.??? Even after I switched to 64MB for memcached.
    I’ll play with it again tonight,
    thanks for your help.

  • atulaus

    help me
    Page caching is not working properly. Memcached server(s): may not running or not responding. This error message will automatically disappear once the issue is resolved.

    i user Centos + nginx + W3 Total Cache

    • Ruchira

      how did you installed memcached?

      • atulaus

        yes i installed memcached but not installed sucsecfull
        help me

        • Ruchira

          what is the way did you installed memcached?

  • Bojan

    This plugin ”WP Memcached Manager” not works on WP 3.5.1????

    • Ruchira

      yeah had the same problem :(

Previous post:

Next post: