The right way to Set up and Configure Memcached on Ubuntu

Memcached is a free and opensource in-memory caching system that accelerates net functions by caching massive volumes of information in reminiscence which might be generated from web page load requests or API calls. Memcached is especially helpful in rushing up PHP-based net functions resembling WordPress, Joomla, Drupal, and Python functions as properly.

On this tutorial, we take a look at how one can set up Memcached on Ubuntu. For demonstration functions, we are going to use Ubuntu 20.04 Focal Fossa. Granted, the identical information will apply for Ubuntu 16.04 and later variations.

Conditions

As we transfer alongside, guarantee you could have the next in examine:

Let’s now roll our sleeves and dive in.

Putting in Memcached in Ubuntu Server

Earlier than putting in Memcached, let’s first replace the package deal record of the packages put in utilizing apt command.

$ sudo apt replace

Update Ubuntu 20.04 Server

Replace Ubuntu 20.04 Server

This could take a minute or two relying on the pace of your web connection. As soon as the replace is full, set up Memcached by operating the command beneath. It will set up Memcached alongside different dependencies and packages.

$ sudo apt set up memcached libmemcached-tools

Install Memcached in Ubuntu 20.04

Set up Memcached in Ubuntu 20.04

When prompted, press ‘Y’ on the keyboard and hit ENTER to proceed with the set up.

As soon as put in, the Memcached service ought to begin mechanically. This may be verified by checking the standing of Memcached as follows.

$ sudo systemctl standing memcached

Check Memcached Status

Verify Memcached Standing

The output confirms that Memcached is up and operating.

Configuring Memcached in Ubuntu

The default configuration file for Memcached is /and so on/memcached.conf. It’s additionally necessary to say that by default, Memcached listens on port 11211 and is configured to hear on the localhost system. You’ll be able to verify this by checking the configuration file on line 35 as proven.

$ sudo nano /and so on/memcached.conf

Check Memcached Configuration

Verify Memcached Configuration

If the appliance connecting to the Memcached service is sitting on the identical server the place Memcached is put in, then there’s no must make adjustments to this line. Nonetheless, you probably have a distant shopper that you just wish to permit entry to Memcached caching service, then it is advisable to edit this line & add the distant shopper’s IP handle.

Suppose, you could have a distant shopper with IP 192.168.2.105 operating an utility that wants to hook up with the Memcached service. To permit entry, merely delete the localhost IP handle (127.0.0.1) and substitute it with the distant shopper’s IP handle. The belief right here is that each programs are in the identical Native space community.

-l 192.168.2.105

Configure Memcached Connection

Configure Memcached Connection

Save and exit the configuration file.

Subsequent, restart the Memcached service to use the adjustments.

$ sudo systemctl restart memcached

Lastly, to permit distant connections to the Memcached server, we have to open the Memcached default port – port 11211 – on the firewall.

To attain this run the instructions:

$ sudo ufw permit 11211/tcp

Then reload the firewall to use the adjustments.

$ sudo ufw reload

To confirm that the port is open, execute:

$ sudo ufw standing

Open Memcached Port on UFW Firewall

Open Memcached Port on UFW Firewall

Enabling Memcached for Functions

Relying on the appliance you’re operating, it is advisable to set up a language-specific shopper to allow Memcached to serve the requests.

For PHP functions resembling Joomla or WordPress, execute the command beneath to put in the extra packages:

$ sudo apt set up php-memcached

Install Memcached PHP Extension

Set up Memcached PHP Extension

For Python functions, make sure that the next Python libraries are put in utilizing the pip package deal supervisor.

$ pip set up pymemcache
$ pip set up python-memcached

And this wraps up our matter on how one can set up and configure Memcached on Ubuntu. Your suggestions might be a lot appreciated.

Supply

Germany Devoted Server

Leave a Reply