01 Jan 2025 - by 'Maurits van der Schee'
Memcache is a very fast cache that is a great addition to MariaDB and PHP. It is simpler and more performant than Redis. I prefer Redis for session storage and Memcache for application caching in my (high-performance) PHP projects. Installing Memcache is very easy (on any Debian based Linux), all you have to do is type:
sudo apt install memcached
In order to allow PHP to talk to Memcache you need the "php-memcache
" extension. You can install that with:
sudo apt install php-memcache
Now when you are running PHP 8.3 (the version that is distributed with Linux Mint 22), then you may get this error message:
Creation of dynamic property Memcache::$connection is deprecated
Now check the installed version of the Memcache extension using:
echo '<?php phpinfo();' | php | grep 'memcache support' -A1
You probably see this:
memcache support => enabled
Version => 4.0.5.2
This is due to the version in the repository being a bit behind (4.0.5.2 is from 2019-12-20). You can install this latest version by running:
sudo apt install php-dev zlib1g-dev
sudo apt install php-pear
sudo pecl channel-update pecl.php.net
sudo pecl install memcache
If you installed the latest version it should say:
memcache support => enabled
Version => 8.2
Now all you need to do is restart Apache or any other webserver that you are using:
sudo systemctl restart apache2
That's all. I hope this post helped you!
NB: You may also switch from "Memcache" to "Memcached".
PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.