How to Install Memcached on Ubuntu 16.04 / 14.04 / LinuxMint 18 / 17
Memcached is a 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.
It 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.
Here, we will go through the steps to install Memcached on Ubuntu and Linux Mint operating system.
Open Terminal ( Ctrl + Alt + T ).
Install Memcached
Install Memcached using the following command.
sudo apt-get install -y memcached
Edit the Memcached configuration file to change / enable the features.
sudo nano /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 #-l 127.0.0.1
Start Memcached.
sudo service memcached start
To auto-start Memcached on booting.
sudo chkconfig memcached on
Confirm the Memcached running status.
echo stats | nc localhost 11211
Output:
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 END
Install PHP Module
Install Memcached PHP module to work with PHP5.
sudo apt-get install -y apache2 php php-memcache libapache2-mod-php
Now restart the Memcached and Apache server to take effect.
sudo service memcached restart sudo service apache2 restart
That’s all.