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- https://www.ruchirablog.com/nginxmysqlphpfpm-auto-installer-centos-5-debian/

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 http://wordpress.org/extend/plugins/wp-memcached-manager/ ( For viewing memcached data without log in to SSH)
  2. W3 Total Cache http://wordpress.org/extend/plugins/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
Ruchira
View all posts by Ruchira

{ 32 comments… read them below or add one }

1 Brandy Watcerson November 4, 2010 at 6:16 AM

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 πŸ™‚

Reply

2 Dudeist December 3, 2010 at 10:51 PM

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.

Reply

3 Ruchira December 4, 2010 at 3:21 AM

Hi,
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! πŸ™‚

Reply

4 Dudeist December 4, 2010 at 10:50 AM

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

Thanks again.

Reply

5 Ruchira December 4, 2010 at 8:16 PM

success? πŸ™‚

Reply

6 bagus January 13, 2011 at 6:27 PM

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

Reply

7 bagus January 13, 2011 at 6:46 PM

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

Reply

8 Ruchira January 13, 2011 at 7:18 PM

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

Reply

9 Ruchira January 13, 2011 at 7:17 PM

I have it unchecked πŸ™‚

Reply

10 Damir-ElggFactory January 22, 2011 at 1:51 PM

Ruchira,

In Memcached Manager when adding server I see you have 127.0.0.1 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): 127.0.0.1:11211 may not running or not responding.”

When I ran this in shell:
telnet 127.0.0.1 11211 β€”-> β€œUnable to connect to remote host: Connection refused.

so port is blocked?… what do I do?

Reply

11 Ruchira January 22, 2011 at 9:24 PM

how did you installed memcached and whats your OS?

Reply

12 Damir-ElggFactory January 22, 2011 at 10:18 PM

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?
Thanks

Reply

13 Ruchira January 22, 2011 at 10:27 PM

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!

Reply

14 Damir-ElggFactory January 22, 2011 at 11:53 PM

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
?

Reply

15 Ruchira January 23, 2011 at 1:08 AM

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

deb http://ftp.si.debian.org/debian lenny main
deb http://security.debian.org/ lenny/updates main
deb http://volatile.debian.org/debian-volatile lenny/volatile main contrib non-free
deb ftp://ftp.gplhost.fr/debian 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!

Reply

16 Damir-ElggFactory January 23, 2011 at 8:57 AM

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?

Thanks.

Reply

17 Ruchira January 24, 2011 at 7:59 AM

Try this

wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar xzf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure && make && sudo make install

Reply

18 Damir-ElggFactory January 24, 2011 at 2:10 PM

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): 127.0.0.1:11211 may not running or not responding.”

Reply

19 Ruchira January 24, 2011 at 7:07 PM

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!

Reply

20 Damir-ElggFactory January 24, 2011 at 7:30 PM

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

Reply

21 Ruchira January 24, 2011 at 8:02 PM

default port is 11211 if you didnt changed it!

Reply

22 Damir-ElggFactory January 24, 2011 at 7:46 PM

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?

Reply

23 Ruchira January 24, 2011 at 8:04 PM

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!

Reply

24 Damir-ElggFactory January 24, 2011 at 8:29 PM

ok,

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.

Reply

25 Ruchira January 25, 2011 at 8:55 AM

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.

Reply

26 Damir-ElggFactory January 25, 2011 at 9:58 AM

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.

Reply

27 atulaus April 16, 2011 at 3:24 AM

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

i user Centos + nginx + W3 Total Cache

Reply

28 Ruchira April 16, 2011 at 8:57 AM

how did you installed memcached?

Reply

29 atulaus April 17, 2011 at 2:27 PM

yes i installed memcached but not installed sucsecfull
help me

Reply

30 Ruchira April 17, 2011 at 7:01 PM

what is the way did you installed memcached?

Reply

31 Bojan March 14, 2013 at 9:50 AM

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

Reply

32 Ruchira March 19, 2013 at 7:55 AM

yeah had the same problem πŸ™

Reply

Leave a Comment

Previous post:

Next post: