Install memcache and setup with Magento2

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

To

-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/php.in

Change the statement from

[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
session.save_handler = files

To

[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
;session.save_handler = files
session.save_handler = memcached 
session.save_path = "127.0.0.1:11211"

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',
  ),

To

'session' =>
   array (
      'save' => 'memcached',
      'save_path' => '127.0.0.1:11211'
  ),

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 127.0.0.1 11211

At the prompt, enter

stats items

Output something like-:

Trying 127.0.0.1...
Connected to 127.0.0.1.
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
END

Leave a Reply