How To Install Memcached on Debian
In this tutorial we are going to explain How To Install Memcached on Debian.
What is Memcached?
Memcached is a cache system for high performance distributed memory objects, of a generic nature, which was originally developed to be used in the acceleration of dynamic web applications optimizing the load of the database.
Now, we will see how to install memcached on Debian.
Root User & Update Debian
The first step to take is to change the user to root, if not already, and for that it is enough to execute one of the following commands:
su – or sudo su -l
The next step is to update the available packages of Debian 9 and for this we will execute the following lines:
apt-get update apt-get upgrade
Install Memcached on Debian 9
Once the operating system is updated, we proceed to install memcached which is available in the Debian repositories, for this we will execute the following line:
apt-get install memcached netcat
Once memcached is installed we proceed to validate if the service has been started or not, for this we will execute the following:
ps -ef | grep -i memcached
The result obtained will be the following:
Configuring Memcached on Debian 9
Once we validate that the service is active, the next step is to configure the application and its configuration file is found in the path /etc/memcached.conf.
Access to it using the preferred editor:
There we can change the desired values being the memory cache one of the most common, we place the memory line and the default value is 64 but we can set the desired one such as 256 or 512.
Save the changes using the key combination Ctrl + O and exit the editor using the combination Ctrl + X.
Restart the Memcached process by executing the following:
systemctl restart memcached
Enable the memcached autostart by executing:
systemctl enable memcached
If we want to confirm the memcached status we will execute the following line:
echo "stats settings" | nc localhost 11211
As a result, we will obtain the value of each of the configuration parameters of the application:
Firewall Config in Debian 9
Now we must enable port 11211 as an incoming connection in the firewall so that everything works properly and for this we execute the following:
firewall-cmd --permanent --zone=public --add-port=11211/tcp firewall-cmd –reload
if we use UFW:
ufw allow 11211/tcp ufw reload
If we want to check the remote connectivity we will execute the following:
echo stats | nc host_memcached_o_IP 11211
PHP Module Install
Finally it will be necessary to install the PHP module for the optimal functioning of memcached with PHP. We will execute the following line:
apt-get install -y php php-memcache
Now we must restart the memcached and Apache services for the changes to take effect:
systemctl restart memcached systemctl restart apache2
To test the PHP configuration we will create a file called info.php by accessing the following path:
In this new file we will enter the following:
<? php phpinfo (); ?>
Save the changes with the Ctrl + O keys and exit using Ctrl + X.
Now we go to the browser and enter the following syntax:
This will be the result
In this way we have installed and configured memcached in Debian9.