Install Memcached on Linux Mint 12 / Ubuntu 11.10 / 12.04

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 APIis available for most popular languages.

Here is the simple steps to install Memcached on Linux Mint and Ubuntu operating system.

Open Terminal ( Ctrl + Alt + T ).

Install Memcached:

Install Memcached using the following command.

raj@geeksite~/$ sudo apt-get install memcached

Edit Memcached configuration file to change / enable the features.

raj@geeksite~/$ sudo gedit /etc/memcached.conf

There are some default settings available in the configuration file, change it (if necessary). The following are example settings for 64MB caching, need to comment out the listening ip address to listen on all ip address.

# memory
-m 64
# Default connection port is 11211
-p 11211
# -u command is present in this config file
-u memcache
# listening ip address

Start Memcached.

raj@geeksite~/$ sudo /etc/init.d/memcached start

To auto-start Memcached on booting.

raj@geeksite~/$ sudo chkconfig memcached on

Confirm the Memcached running status.

raj@geeksite~/$ echo stats | nc localhost 11211
STAT pid 1370
STAT uptime 2119
STAT time 1331977895
STAT version 1.4.7
STAT libevent 2.0.12-stable
STAT pointer_size 32
STAT rusage_user 0.084005
STAT rusage_system 0.000000
STAT curr_connections 10
STAT total_connections 13
STAT connection_structures 11
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 18
STAT bytes_written 1635
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0

Iptables entry:

Add the following entry to allow the incoming connection on port no 11211.

-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT

Check the remote connectivity.

raj@geeksite~/$ echo stats | nc memcache_host_name_or_ip 11211

Install PHP Module:

Install Memcached PHP module to work with PHP5.

raj@geeksite~/$ sudo apt-get install php5 php5-memcache

Now restart the Memcached and Apache server to take effect.

raj@geeksite~/$ sudo /etc/init.d/memcached restart
raj@geeksite~/$ sudo /etc/init.d/apache2 restart

That’s all!


Share This Post