Install Memcached on a Linux server running Ubuntu 20.04 LTS

News Summary:

  • When connecting to the Memcached server, the connection is made using the PROTOCOLS TCP and IP, and data is delivered with a distinct key value and saved as strings in memory. Both permanent and temporary data can be saved. In the case of temporary storage, the data that has been cached will be automatically deleted after the specified amount of time.

  • Many businesses and website owners utilise Memcached, a published cache server with a BSD licence, to swiftly recover data from memory. Many users have used it to increase the speed and efficiency of their dynamic websites with database connectivity. Performance can be increased by reducing the number of times complex and frequently used database queries, particularly SELECT statements, are called or by storing important data in memory instead of accessing the disc.

Run the given command in the terminal of your Ubuntu 20.04 LTS server to install the most recent system updates.

Let’s examine the Memcached server version that is installed on our system right now. The command to verify the MemCached service’s status is also covered here.

Memcached Server is already included in the default repository for Ubuntu 20.04, therefore we don’t need to add any additional third-party repositories to install it. Therefore, we can configure this cache server on our system using the APT package manager and the accessible package names.

For service status:

The above command will tell us whether the service of our cache server is running actively or not; including which IP address can access it at what port number.

If you want to use Memcached on Ubuntu 20.04 for PHP-based applications such as WordPress, Magento, and others, then we have to install an extension called php-memcached. It can easily be installed using the APT package manager. Here is the command:

Note: The above command must run on the Ubuntu or Debian server where you are hosting your PHP application.  And we are also assuming that you already have PHP installed. If you don’t have PHP then run this command: sudo apt install apache2 php libapache2-mod-php php-memcached php-cli

To confirm our installation Memcached on Ubuntu 20.04 and its extension is working for the PHP application, we can create info.php file on the server where Apache and PHP are installed. Paste this code:

Save the file using Ctrl+O, hit the Enter key, and then exit the text editor using Ctrl+X. After that open your browser and point to the created file: http://server-ip-address/info.php

Scroll down and you will find a section showing details related to Memcached. This means the extension is enabled and working for PHP. Now, let’s confirm further whether this caching server is really storing our data temporarily in the memory to speed up the performance of our PHP applications or not. For that create a Test.php file.

Copy-Paste the following in the files Save the file using Ctrl+O, hit the Enter key, and then exit the text editor using Ctrl+X.