How to use Memcache in Magento 2 in Ubuntu

Use Memcache in Magento2 in Ubuntu

Here are 2 steps for you know How to use Memcache in Magento 2 in Ubuntu:

  • Step 1: To install and configure Memcached on Ubuntu
  • Step 2: To configure Magento to use Memcache

Step 1 :To install and configure memcached on Ubuntu

1.As a user with root privileges, enter the following command:

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

2.Change the memcached configuration setting for CACHESIZE and -l:

  1. Open /etc/memcached.conf in a text editor.
  2. Locate the -m parameter and change its value to at least 1GB
  3. Locate the -l parameter and change its value to or localhost
  4. Save your changes to memcached.conf and exit the text editor.
  5. Restart memcached.
  6. service memcached restart

3.Restart your web server: service apache2 restart

Step 2: To configure Magento to use memcache

1.Open <your Magento install dir>/app/etc/env.php

2.Locate 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. Delete the contents of the following directories under your Magento installation directory:
  2. rm -rf var/cache/* var/page_cache/* var/session/*
  3. Go to any page on the storefront.
  4. Log in to the Magento Admin and browse to several pages.
  5. If no errors display, congratulations! memcached is working

Following these steps can help you to use Memcache in Magento2 in Magento2.

For more Magento KB, visit Webnexs Magento Knowledge Base.





Leave a Reply

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