How to use memcache in magento 2 in Ubuntu

The following steps show you how to use memcache in magento 2 in ubuntu

Step 1: To install and construct the memcached on ubuntu .

Step 2:  to construct magento to use memcached.

To install and construct the memcached on ubuntu

As a user with root rights ,enter the following commands

apt-get -y update
apt-get -y install php5-memcache memcached

Modify the memcached   configuration setting of CACHESIZE and –I:

  1. Open /etc/memcached.con in the text editor.
  2. Place the –m parameter and modify its value to alteast 1GB
  3. Save your changes to memcached.conf and exit text editor
  4. Restart memcached.
  5. Regenerate Service memcached

To construct magento to use memcached

  1. Open <your Magento install dir>/app/etc/env.php
  2. set the following
'session' =>

   array (

   'save' => 'files',


 Change it as follows:

'session' =>

  array (

     'save' => 'memcache',

     'save_path' => 'tcp://<memcache ip or host>:<memcache port>'


 To verify memcached works with magento:

  1. Erase the contents of the following directories under your Magento installation directory:
rm-rf-Var/cache/* var/page_cache/* var/session/*
  1. go to any page on the storefront
  2. log in to Magento Adminstration and browse to more pages
  3. If no error display, well done! Memcached is working

I hope the following guidelines help  you use memcache in magento 2 in Ubuntu.






Leave a Reply

Your email address will not be published. Required fields are marked *