Table of Contents
Today in this article we are going to show you how to Install Memcached on Linux server running Ubuntu 20.04 LTS. Many companies and website owners use Memcached, a published BSD licensed cache server, to quickly retrieve data from memory. Many users have used it to increase the speed and efficiency of their dynamic websites with database connectivity. This was done by minimizing the use of complex and frequently used database queries, particularly select statements, or by avoiding disk access and storing crucial data in memory.
When connecting to the Memcached server via TCP and IP protocols, data is provided with a unique key value and stored as strings in memory. Stored data can be permanent or temporary. Well, in case of staging, cached data will be deleted automatically after the configured time interval.
We don’t need to add any additional 3rd party repositories to install Memcached Server because it is already included in the default Ubuntu 20.04 repository. So using APT package manager and available package names we can configure this cache server on our system. We have mentioned below the steps to install Memcached on Linux server running Ubuntu 20.04 LTS.
Steps to Install Memcached on Linux Server Running Ubuntu 20.04 LTS
Installing Memcached
Step 1: if you still don’t have memcached installed on your server, you can install it from official Ubuntu repositories. First make sure your local package index is updated using the following command:
sudo apt update
Step 2: Next, install the official package as follows:
sudo apt install memcached
Step 3: You can also install libmemcached-tools, which is a package that contains various tools that you can use to examine, test, and manage your Memcached server. Add the package to your server with the following command:
sudo apt install libmemcached-tools
Step 4: Memcached should now be installed as a service on your server, along with tools that will allow you to test your connectivity.
Step 5: For start memcachedrun the following systemctl command:
sudo systemctl start memcached
Configuring Memcached Network Settings
Step 1: The default Memcached configuration file is located at /etc/memcached.conf. You can configure it according to your needs. The default settings are sufficient for most applications. However, if you want to allow remote access to your Memcached server and change the default port, edit the Memcached configuration file as shown below:
nano /etc/memcached.conf
Step 2: change the following values:
# The default connection port is 11211-p 11211
-l your-ip-server
# Limit the number of simultaneous incoming connections. The daemon default is 1024-c 1024
Step 3: Save and close the file then restart the Memcached service to implement the changes.
systemctl restart memcached
Step 4: Now you can check Memcached status with the following command:
memcstat –servers=your-ip-server
Configure PHP to use Memcached
At this point, Memcached is installed and configured. Now, you can configure PHP to use Memcached.
Step 1: First, install Apache and PHP modules with the following command:
apt-get install apache2 libapache2-mod-php php php-cli php-memcached -y
Step 2: Next, create a sample PHP file in the Apache root directory with the following command:
nano /var/www/html/phpinfo.php
Step 3: Add the following code:
Step 4: Save and close the file then restart the apache service to implement the changes:
systemctl restart apache2
Step 5: If you want enable Python supportinstall the following package:
apt-get install python3-pymemcache -y
Step 6: If you want enable perl supportinstall the following package:
apt-get install libcache-memcached-libmemcached-perl -y
Final Words
We hope you like our article on how to Install Memcached on Ubuntu 20.04 LTS Linux Server. Memcached is an all-purpose, high-performance distributed memory caching technology that is open source. It is a RAM-based key-value store for short, arbitrary blocks of data that is used to speed up dynamic websites. If read requests for your web application are high and writes are low, Memcached is an excellent tool for you.