Skip to main content

How To Install and Secure Memcached on Ubuntu 16/18.04 ?

Memcached is an open-source memory caching system that you can use to speed up web applications and dynamic websites. Memcached works by storing frequently accessed data in RAM hence reducing the time an application reads data from databases, files or API interfaces. If your website, web application or API server has high read calls and infrequent writes, Memcached can be a great tool for you. 

Install Memcached and Client Library 
# sudo apt install memcached libmemcached-tools
# sudo systemctl status memcached 
Securing Memcached Configuration Settings
# vi /etc/memcached.conf
-d
-vv
-m 256
-p 11211
-u memcache
-l 127.0.0.1 
add the following option to the bottom of this file:
-U 0 
Restart your Memcached service to apply your changes:
# sudo systemctl restart memcached 
Verify that Memcached is currently bound to the local interface and listening only for TCP connections by typing:
# sudo netstat -plunt 
To check that Memcached is up and running, type the following:
# memcstat --servers="127.0.0.1" 
Next, run the command below to verify that Memcached server is working as expected on your server.
# echo stats | nc 127.0.0.1 11211 
You can also check whether the Memcached service is running by typing:
# ps aux | grep memcached 
PHP : To use Memcached as a caching database for your PHP application such as WordPress , Drupal , Joomla or Magento , you need to install the php-memcached extension:
# sudo apt install php-memcached 

Comments