admin/ April 25, 2016/ Linux, Magento2/ 0 comments

Install Memcache on Ubuntu and setup with Magento2 (M2).

There are few steps below.

Step 1-:
Install Memcache required packages.

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

Open the Memcache configuration, Increase the memory size to 1GB.

$ sudo nano /etc/memcached.conf

Replace the line from

-m 64


-m 1024

Restart memcache

$ sudo service memcached restart

Step 2-:
Open the php.ini and configure the php session to memcache.

$ sudo vi /etc/php5/apache2/

Change the statement from

; Handler used to store/retrieve data.
session.save_handler = files


; Handler used to store/retrieve data.
;session.save_handler = files
session.save_handler = memcached 
session.save_path = ""

Step 3-:

Configure the Magento2 for memcache.
Open env.php of Magento2 instance

$ sudo nano /var/www/html/app/etc/env.php

Replace the line from

'session' => 
  array (
    'save' => 'files',


'session' =>
   array (
      'save' => 'memcached',
      'save_path' => ''

Step 4-:

Clean the Magento2 cache.

cd /var/www/html/
rm -rf var/cache/* var/page_cache/* var/session/*

Restart Apache Server.

$ sudo service apache2 restart

Additional Step-:
To check the memcache.

telnet 11211

At the prompt, enter

stats items

Output something like-:

Connected to
Escape character is '^]'.
stats items
STAT items:10:number 1
STAT items:10:age 8
STAT items:10:evicted 0
STAT items:10:evicted_nonzero 0
STAT items:10:evicted_time 0
STAT items:10:outofmemory 0
STAT items:10:tailrepairs 0
STAT items:10:reclaimed 0
STAT items:10:expired_unfetched 0
STAT items:10:evicted_unfetched 0
Share this Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.