Web Hosting Web Hosting Tips and Tutorials

Adding memcache to CentOS 6.5+

Written by Tom Eagles

What is Memcached?

Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.

Memcache can be used in conjuction with some of the more popular WordPress caching plugins such as W3 Total Cache to reduce the loading times of your posts and pages to your visitors.

Instead of every time a page or post is loaded the result of the database query which generated the page is stored in RAM on the server so the next visitor receives the result without the database query being run.

The instructions below are for those managing their own dedicated server Running CentOS 6.5+, those with managed servers or VPS or other types of hosting will need to contact their web hosts for details.

Adding memcache to CentOS 6.5+

  • Step 1: SSH into your server and fire this command yum install memcached.x86_64
  • Step 2: Next still in ssh install the memcache php extension pecl install memcache
    Restart apache: service httpd restart
  • Step 3: Start memcache by firing this command: memcached -d -m 2048 -l 127.0.0.1 -p 11211 -u nobody
    Syntax: (d = daemon, m = memory, u = user, l = IP to listen to, p = port)
  • Step 4:¬†Check your memcached server is running successfully: ps -eaf | grep memcached
  • Step 5: make it so it comes on at reboot using: chkconfig memcached on
  • Step 6: In above step three we set the memcache at 2048 ( -m 2048 ) but this is not permanent and will reset back to default which is 64. To make the memcache the size you prefer permanent even after a reboot adjust the setting in the /etc/sysconfig/memcached file and adjust as needed. Restart memcached to see what the memcache size will be after a reboot – service memcached restart The below example shows the¬†/etc/sysconfig/memcached file we are provisioned for 2048 MB’s of memcached

Example of memcached configuration file provisioned for 2048 MB’s of memcached:

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="2048"
OPTIONS="-l 127.0.0.1"

NOTE: The last line OPTIONS is set to allow only access to memcached by the server itself basically securing memcached and its data from being manipulated by the outside world.

About the author

Tom Eagles

Leave a Comment

Pin It on Pinterest

Share This

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!