Let me give you an example of installing Memcached, which allows you to cache data in RAM.
In Ubuntu/Debian, memcached can be installed using the following commands (as well as installing a set of useful utilities):
sudo apt update
sudo apt install memcached libmemcached-tools
Open the configuration file in any text editor:
sudo nano /etc/memcached.conf
For security purposes, disable the UDP protocol, for this, add at the end of the file:
-U 0
You can also allocate more RAM, for example 1Gb:
-m 1024
Restart memcached to apply the changes:
sudo systemctl restart memcached
If you need to use memcached with Apache2 or Nginx (php-fpm), then install the php extension and restart the web server:
sudo apt install php-memcached
sudo systemctl restart apache2
sudo systemctl restart php7.2-fpm
Make sure memcached only works on the local interface (by default on port 11211):
sudo netstat -plunt | grep memcached
sudo ps ax | grep memcached
sudo systemctl status memcached
You can see the statistics like this:
memcstat --servers="127.0.0.1"
echo "stats settings" | nc localhost 11211
You can also create a php file with the content below and open it in a browser to view memcached parameters:
<?php
phpinfo();
?>
See also my articles:
Installing WordPress and Nginx
Simple page caching