Enable memcached on Magento 2 in Plesk Server
To install memcached, run
1 2 3 |
apt install php-memcached apt install build-essential apt install autoconf automake gcc libmemcached-dev libhashkit-dev pkg-config plesk-php*-dev zlib1g-dev |
Enable memcached php module
1 |
/opt/plesk/php/7.3/bin/pecl install memcached |
This is for PHP 7.3, change the path to pecl for your version of PHP.
Activate memcached
1 |
echo "extension=memcached.so" > /opt/plesk/php/7.3/etc/php.d/memcached.ini |
Update php handler
1 |
plesk bin php_handler --reread |
Restart php-fpm
1 2 |
systemctl stop plesk-php73-fpm.service systemctl start plesk-php73-fpm.service |
Install memcached deamon
1 |
apt install memcached |
Restart memcached
1 2 |
systemctl enable memcached systemctl restart memcached |
Verify it is working with netstat
1 2 3 |
malta2032:~# netstat -lntp | grep mem tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 30204/memcached malta2032:~# |
Activate memcached in Magento 2
Edit file
1 |
vi app/etc/env.php |
Find
1 2 3 |
'session' => [ 'save' => 'files' ], |
Replace with
1 2 3 4 |
'session' => [ 'save' => 'memcached', 'save_path' => '127.0.0.1:11211' ], |
If you get error like
1 |
Warning: SessionHandler::read(): open(127.0.0.1:6379/sess_0s39482mnk2hhoflf4d6odjuv2, O_RDWR) failed: No such file or directory (2) in /vendor/magento/framework/Session/SaveHandler/Native.php on line 22 |
edit your php.ini and set “session.save_handler” from “files” to “memcached”.
See if memcached working
To see if memcached is caching, you can use
1 2 |
telnet 127.0.0.1 11211 stats items |
To exit, type
1 |
quit |