Check Memcached Service and version

How to install Memcached on Ubuntu 22.04 LTS Server

Posted on

Steps and instructions to put in and configure Memcached on Ubuntu 22.04 LTS Jammy JellyFish to cache knowledge for PHP or Python-based functions. 

Memcached is a BSD-licensed revealed cache server utilized by many organizations and web site house owners to shortly retrieve knowledge from reminiscence. It has been utilized by many customers to enhance the general velocity and efficiency of their dynamic web sites with database connectivity to enhance efficiency by avoiding disk entry and storing vital knowledge in reminiscence or by minimizing the decision of advanced and ceaselessly used database queries – particularly SELECT statements.

Knowledge is supplied with a singular key worth and saved as strings in reminiscence whereas the connection takes place to the Memcached server through the PROTOCOLS TCP and IP. The saved knowledge may be both everlasting or non permanent. Effectively, within the case of non permanent storage, the deletion of cached knowledge will occur mechanically after the configured interval of time.

Steps to put in Memcached Server on Ubuntu 22.04 LTS

Estimated studying time: 7 minutes

1. Replace Ubuntu 22.04

Entry the terminal of your Ubuntu 22.04 LTS server and run the given command to put in the newest updates obtainable for the system.

sudo apt replace

2. APT to Set up Memcached on Ubuntu 22.04

We don’t want so as to add any third-party repository to put in Memcached Server on Ubuntu 22.04 as a result of it’s already obtainable via the system’s default Repo. Therefore, we will use the APT bundle supervisor with the bundle names obtainable to configure this cache server on our system.

Observe: The second bundle we have now put in utilizing the below-given command i.e libmemcached-tools supplies a command line utility to handle the cache server utilizing the terminal of Ubuntu.

sudo apt set up memcached libmemcached-tools

3. Examine Service and model on Ubuntu 22.04

Now, let’s examine which model of the Memcached server is on our system. Can even study right here the command to examine the standing of the MemCached service.

memcached -V

For service standing:

systemctl standing memcached -V

The above command will inform us whether or not the service of our cache server is working actively or not; together with which IP handle can entry it at what port quantity.

Check Memcached Service and version

4. To allow Memcached for PHP functions

If you wish to use Memcached on Ubuntu 22.04 for PHP-based functions similar to WordPress, Magento, and others, then we have now to put in an extension known as php-memcached. It could possibly simply be put in utilizing the APT bundle supervisor. Right here is the command:

sudo apt set up php-memcached

Observe: The above command should run on the Ubuntu or Debian server the place you’re internet hosting your PHP utility.  And we’re additionally assuming that you have already got PHP put in. Should you don’t have PHP then run this command:

sudo apt set up apache2 php libapache2-mod-php php-memcached php-cli

5. Examine Memcached is working for PHP

To verify our set up of Memcached on Ubuntu 22.04 and its extension is working for the PHP functions, we will create data.php file on the server the place Apache and PHP are put in.

sudo nano /var/www/html/

Paste this code:

// Present all info, defaults to INFO_ALL

Save the file utilizing Ctrl+O, hit the Enter key, after which exit the textual content editor utilizing Ctrl+X.

After that open your browser and level to the created file: http://server-ip-address/data.php

Scroll down and one can find a piece exhibiting particulars associated to Memcached. This implies the extension is enabled and dealing for PHP.

Check Memcached is working for PHP Ubuntu 22.04

6. Verify whether or not Memcached is caching or not

Now, let’s verify additional whether or not this caching server is storing our knowledge briefly within the reminiscence to hurry up the efficiency of our PHP functions or not. For that create a Check.php file.

sudo nano /var/www/html/take a look at.php

Copy-Paste the next within the file



$memcached = new Memcached();
$memcached->addServer("", 11211); 
$response = $memcached->get("key_cache");

echo "Consequence coming from caching";
echo $response;


echo "Cache isn't created but, reload once more to see adjustments";
$memcached->set("key_cache", "Hooray! Memcache is working now ...") ;
catch (exception $e)
echo $e->getMessage();

Save the file utilizing Ctrl+O, hit the Enter key, after which exit the textual content editor utilizing Ctrl+X.

Now, open your browser and level to your created Check.php file:

http://your-server-ip-address/take a look at.php

You will notice the output exhibiting “Cache isn’t created but, reload once more to see adjustments...” Reload the Check.php web page.

PHP script to check memcached

If the cache server is working effective then you will note the next output:

“Consequence coming from caching. Hooray! Memcache is working now…’

Confirm Memcached is caching or not on Ubuntu 22.04

7. For Distant Server

Effectively, by default the Memcached server on Ubuntu 22.04 listens to localhost solely which implies if each Memcached and the applying similar to WordPress are put in on the identical server then this setting is totally effective. Nonetheless, in case your PHP or Python utility is put in on some distant server that desires to make use of the Memcached service put in on another system then we have now to configure it for that.

Merely, edit the configuration file of your cache server, right here is the command for that:

sudo nano /and so forth/memcached.conf

Scroll down and discover a line -l and exchange the with the IP handle of the distant server the place your utility is working that want a caching service.

memcached remote server configuration

For instance, if the IP is then it seems to be like this fashion: -l

Save the file utilizing – Ctrl+O, press Enter key, and exit- Ctrl+X,

Additionally, don’t neglect to permit TCP port 11211 in your VPS or cloud internet hosting firewall. If you’re utilizing Ubuntu’s UFW firewall then it’s important to open the port in that for distant connection; use the given command:

sudo ufw permit 11211/tcp

8. Allow Memcached of Python Apps (optionally available)

Those that are utilizing Python-based internet functions and wish to use Memcached for them can set up the required library utilizing the PIP bundle supervisor of Python.

pip set up pymemcache
pip set up python-memcached

9. Memcached Command line

To make use of the command line for configuring Memcached, use its command line. For that merely sort:

memcached –choice

To know what Choices can be found to make use of, see its assist part:

memcached -h
Memcached Command line Ubuntu 22.04

10. Uninstall Memcached on Ubuntu 22.04

Those that wish to take away this cache server utterly from their Ubuntu 22.04 system for any cause can use the given command:

sudo apt autoremove --purge memcached libmemcached-tools


What’s Memcached used for?

Memcached is an open-source distributed memory-caching system used to extend the efficiency of internet functions by storing knowledge from the database in RAM. It may be used for caching classes, internet pages, API, question outcomes, and different objects similar to photos, information, and metadata.

Is Memcached free?

Memcached is a free and open-source caching server and therefore completely free to make use of for private and industrial functions with out paying any prices.

Is Memcached NoSQL?

Sure, Memcached is a NoSQL knowledge administration answer as a result of it makes use of a key-value knowledge mannequin. It makes use of the RAM to retailer knowledge and enhance the efficiency of information switch when known as by the consumer in an internet utility for instance a WordPress-based web site.

Can we use Memcached on Docker?

Sure, we will use Memcached on Docker. Merely use the pre-built picture of this caching system obtainable within the Docker library to create a container after which level to your server that wants its caching service.

Different Articles:

Install PostgreSQL 13 on Ubuntu 22.04 LTS Linux
Install Python 3.9 or 3.8 on Ubuntu 22.04 LTS Jammy JellyFish
2 ways to Install Cassandra on Ubuntu 22.04 LTS Jammy
Install PrestaShop on Ubuntu 22.04 Server
How to install Linux kernel 5.19 on Ubuntu 22.04 or 20.04

offshore vps