Memcached is a software that implements a RAM caching service based on a hash table.

You can also install this application at one-click checkout
Detailed description of this One-Click-Apps

Memcached is a server that stores some data in RAM with a specified lifetime. The data is accessed by a key (name). You can think of Memcached as a hash table stored on the server. It's mostly used to cache web page code, database query results, etc.

Before installing it, let's update the system:

# apt-get update && apt-get upgrade

Now use the following command to install memcached and the memcache module for PHP:

# apt-get install memcached php5-memcache

Next, we check to see if the daemon is running

# netstat -tap | grep memcached
tcp 0 0 0 localhost:11211 *:* LISTEN 21488/memcached  

By default, memcached port 11211 with IP:127.0.0.1 (localhost)

It is also possible to edit these settings, e.g. you want to open access from an external IP, you need to edit the memcached settings file - /etc/memcached.conf.

-l 127.0.0.1

parameter is responsible for the IP address that the memcached daemon is listening to.

-m 256

parameter specifies how much memory to allocate for caching in megabytes.

-p 11211

standard port that the memcached daemon listens on.

Next, we need to reboot the web server to connect the memcache module

/etc/init.d/apache2 restart

Or restart the configuration file itself:

/etc/init.d/memcached restart

Configure the firewall for Memcached

Add the following rules to allow connections (for memcached to work):

iptables -A INPUT -p tcp --destination-port 11211 -m state --state NEW -m iprange --src-range 111.161.1.10-111.161.1.15 -j ACCEPT  
iptables -A INPUT -p udp --destination-port 11211 -m state --state NEW -m iprange --src-range 111.161.1.10-111.161.1.15 -j ACCEPT  

open all outgoing ports

iptables -P OUTPUT ACCEPT  

Open port 80 for all incoming connections

iptables -A INPUT -dport 80 -j ACCEPT  

Open ports 22 and 5432 only for a specific IP

iptables -A INPUT -m multiport -dports 22,5432 -s IP_ADDRESS -j ACCEPT  
Updated Feb. 11, 2019