Install Memcached on Fedora 21/20, CentOS/RHEL 7/6.6/5.11

Memcached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load. Memcached is a very useful also in other cases, than only dynamic web applications.

This guide explains howto install Memcached 1.4.15/1.4.17 stable version of distributed memory object caching system on Fedora 21/20/19/18/17/16/15/14/13/12 and CentOS / Red Hat (RHEL) 7/6.6/5.11. Fedora 21/20/19/18/17/16/15/14/13/12, CentOS 7/6 and Red Hat (RHEL) 7/6 has Memcached on default repos, so extra repositories is not needed.

Install Memcached 1.4.15/1.4.17 on Fedora 21/20/19/18/17/16/15/14/13/12, CentOS/Red Hat (RHEL) 7/6.6/5.11

Install Remi repository (not needed on Fedora 21/20/19/18/17/16/15/14/13/12 and CentOS/RHEL 7/6):

Install Memcached package

Fedora 21/20/19, CentOS/Red Hat (RHEL) 7/6.6

CentOS/Red Hat (RHEL) 5.11

Configure memcached

Most important value to configure is CACHESIZE, which is cache size on Megabytes. Example Following configuration use 512 Mb memory for Memcached

Start Memcached

Check that Memcached is Running and Working

Everything working nice. Then it’s time to test memcache example with some web application.

Open Memcached Port (11211) on Iptables Firewall (If the Memcached will also be used other local servers)

Edit /etc/sysconfig/iptables file:

Add following INPUT line:

Restart Iptables Firewall:

Test remote connection:

Install Memcache and/or Memcached PHP Module on Fedora, CentOS and Red Hat (RHEL)

More information about Memcache Module.
More information about Memcached Module.

Install Memcache Module and PHP

Install Memcached Module and PHP

Restart Web server

Share this post

43 Comments

  1. dude !!! fantastic work man…
    you save my time :)

    Reply
  2. i am not get any package, first installation successful, but next command say … no package with php-pecl-memcache availabel … what i do ?

    Reply
    • Hi Anurag,

      Could you post output of following commands:

      Reply
  3. Did the following on Centos 6.4 (also APC installed):
    yum install memcached
    chkconfig memcached on
    service memcached start

    I have checked that Memcached is Running and Working. This seems to be ok.

    But now what? Is it ready to do its job? Do I have to configure anything else? Or is it just eating my RAM without doing anything use full (yet)?

    Reply
    • Hi Karel,

      Sounds okay, but could you tell how much is your memory limit and how much is it using RAM without doing anything?

      Reply
  4. Hi JR, do we need memcached in nginx+php-fpm environment setup?

    Reply
    • Hi Woody,

      Memcached is not required in nginx+php-fpm setup. You can use memcached with php or even with nginx, but it’s not needed if you don’t want to use it.

      Reply
  5. Hi JR, How about Varnish Cache? Unable to search any tutorial about Varnish Cache in your webpage, guess it is a good tool to implement it in apache or nginx website?

    Reply
    • Hi Woody,

      I actually have one draft post, about installing Varnish Cache. Varnish is excellent choice, but many times it’s little bit overkill (and it took a while to get it how very powerful VCL configuration language works) and I have seen people using it totally wrong places, Varnish is excellent if you serve lot of static content. I mean really lot, several thousands hits per second. And yes many users can say that it’s very useful also with small sites, but normally small sites doesn’t have enough resources run Varnish Cache as it should be.

      Many times using Nginx as reverse proxy is very good and much lighter choice. I have used Varnish with this site, but nowadays I prefer Nginx as page cache with conditional passing/purging and CloudFlare service, they have done awesome job and cache nicely all static content. Content delivery works really nice all over the world and it saves lot of bandwidth which is normally expensive.

      Reply
  6. Thank you very much JR.
    Hope to learn more from you in nginx.. :)

    Reply
  7. I get this error.

    Fatal error: Class ‘Memcache’ not found in /opt/lampp/htdocs/memcache/memcache_test.php on line 3

    But I’ve installed Memcached correctly and the php modules memcache and memcached.

    P.S. I’m using a xampp(for linux), running on a Fedora 17.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">