To install memcached, run
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
/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
echo "extension=memcached.so" > /opt/plesk/php/7.3/etc/php.d/memcached.ini
Update php handler
plesk bin php_handler --reread
Restart php-fpm
systemctl stop plesk-php73-fpm.service systemctl start plesk-php73-fpm.service
Install memcached deamon
apt install memcached
Restart memcached
systemctl enable memcached systemctl restart memcached
Verify it is working with netstat
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
vi app/etc/env.php
Find
'session' => [ 'save' => 'files' ],
Replace with
'session' => [ 'save' => 'memcached', 'save_path' => '127.0.0.1:11211' ],
If you get error like
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
telnet 127.0.0.1 11211 stats items
To exit, type
quit
Leave a Reply