Home > LAMP, Web Development > Installing Memcached on Ubuntu

Installing Memcached on Ubuntu

There seems to be confusion between memcache and memcached and there are tutorials all over the internet telling you steps to install memcache/memcached without actually telling what they are.

We need to install 2 things to get memcached working ( I am  on Ubuntu )

  1. The Operating System Library – this is called memcached – there is no choice here, you have to install memcached
  2. Client libraries to access memcached, here you can choose between php-memcache or php-memcached

So PHP has 2 different client libraries ( poorly named as they are confusing ).

Experts on the net say:

  • php-memcache is older and more stable
  • php-memcached is newer but has some additional goodies

Choose what php client to install based on what your application supports. The client libraries are different

I am on 13.04, Raring Ringtail  and  have a running instance of LAMP set up

Installing memcached ( OS library )

sudo apt-get install memcached

memcached details

  • memcached by default runs on port 11211 ( make sure that is open if you have firewall rules )
  • config file is at /etc/memcached.conf

Installing php-memcache (client )

sudo apt-get install php5-memcache

Installing php-memcached ( client )

sudo apt-get install php5-memcached

Restart the apache server

sudo service apache2 restart

To check if memcached is runnig

ps aux | grep memcached

You will see the output similar to this

memcache 17189 0.0 0.0 323228 1172 ? Sl 09:16 0:00 /usr/bin/memcached -m 64 -p 11211 -u memcache -l
root 17219 0.0 0.0 9392 896 pts/1 S+ 09:21 0:00 grep --color=auto memcached

To Increase memory for memcached, open the /etc/memcached.conf and increase the -m parameter
The default is 64M

# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-m 64

Dont forget to restart memcached after config changes
Some basic commands

sudo service memcached restart
sudo service memcached start
sudo service memcached stop

A good Front End for Memcached is phpMemcachedAdmin

Note: This post describes a very basic install and does not take security into consideration. Please secure your memcached on production systems. Some of the techniques can be found on the web like Firewalls, using non-standard ports etc.

Categories: LAMP, Web Development
  1. bhaskar
    December 4, 2013 at 1:26 PM

    Apache Error Warning: PHP Startup: Unable to load dynamic library ‘/opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/memcache.so’ – /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/memcache.so: cannot open shared object file: No such file or directory in Unknown on line 0

    IP is localhost IP

  2. Jinren
    November 20, 2014 at 11:31 PM

    BIG THANK YOU for this article and for clarifying. I was stuck until I found this article. Boos on whoever decided to confuse things with the similar naming.

  1. May 9, 2015 at 12:29 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: