How To Install Memcached on Ubuntu 18.04

How To Install Memcached on Ubuntu 18.04


Memcached is a memory object caching system that allows you to cache information in a memory which is very useful for optimizing websites. It also improves app speeds and prevents poor performance on your dedicated server.


This tutorial will show you how to install and configure Memcached on an Ubuntu 18.04 LTS server.


This guide will assume that you have the basic knowledge of Linux and most importantly, your site is hosted on your own VPS.

  • Ensure your server is set in the root account. If not, you may need to add sudo to your commands to get root privileges.
  • One Ubuntu 18.04 server.

With these essential items in place, you will be ready to start the installation of your Memcached server.

Step 1-
Installing Memcached

To get started with Memcached, gather all the necessary components from the Ubuntu repository. To get the latest components, start by updating your system with the following command:>

$ sudo apt-get update

Now, install Memcached as follows:

$ sudo apt-get install memcached

You can also install libmemcached-tools, which is a library set that features several tools that work well with the Memcached server:

$ sudo apt-get install libmemcached-tools

At this point, Memcached should be successfully installed on your server, along with the essential tools that will allow you to test the connectivity easily. Now, let’s proceed to configure Memcached settings.

Step 2 –
Configuring Memcached

Before configuring Memcached, you need to ensure that it is listening to the local interface For default level configuration, we will check for the following settings under the Memcached configuration file found in /etc/memcached.conf.

The latest version of Memcached that comes with Ubuntu and Debian features the -1 parameter set on the local interface. This parameter defines the IP address to Memcached and prevents denial of service attacks that may come from the network.

We can check this setting to confirm it is working properly:

Use nano to open /etc/memcached.conf file:

$ sudo nano /etc/memcached.conf

To check the interface setting, look for the line below in your file:


. . .

If the setting shows -1, there is no need to modify this line.

Now, save and exit from the file once you’re done.

Go ahead and restart Memcached service to apply these changes:

$ sudo systemctl restart memcached

Confirm that Memcached service is listening to the local interface on TCP connections using the command below:

$ sudo netstat -plunt

You should get the following results:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
. . .
tcp        0      0*               LISTEN      2383/memcached
. . .

This output shows that memcached is on TCP connections through

Step 3 –
Verifying Memcache Setup

To check and verify that your Memcached service is working properly with your machine, run the command below. This will display the current statistics of the Memcached server.

$ echo "stats settings" | nc localhost 11211

You should see the following output:

The values may differ from the results below:

STAT maxbytes 134217728
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter
STAT verbosity 0
STAT oldest 0
STAT evictions on
STAT domain_socket NULL
STAT umask 700
STAT growth_factor 1.25
STAT chunk_size 48
STAT num_threads 4
STAT num_threads_per_udp 4
STAT stat_key_prefix :
STAT detail_enabled no
STAT reqs_per_event 20
STAT cas_enabled yes
STAT tcp_backlog 1024
STAT binding_protocol auto-negotiate
STAT auth_enabled_sasl no
STAT item_size_max 1048576
STAT maxconns_fast no
STAT hashpower_init 0
STAT slab_reassign no
STAT slab_automove 0
STAT lru_crawler no
STAT lru_crawler_sleep 100
STAT lru_crawler_tocrawl 0
STAT tail_repair_time 0
STAT flush_enabled yes
STAT hash_algorithm jenkins
STAT lru_maintainer_thread no
STAT hot_lru_pct 32
STAT warm_lru_pct 32
STAT expirezero_does_not_evict no

Once you’ve verified Memcache setup, install the PHP module for Memcached.

Step 4 –
Installing Memcached PHP Module

On your Ubuntu system, install the current PHP version from ppa:ondrej/php. If you’ve already installed PHP, skip this step.

Otherwise, run the commands below:apt

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install -y php php-dev php-pear libapache2-mod-php

Next, install the required PHP extension for Memcached:

$ sudo apt-get install -y php-memcached

Now, restart Apache to apply the changes:

$ sudo service apache2 restart

Test whether Memcache PHP service is working properly. Make sure you create a test file labelled info.php with the content below:


Now, try to access info.php on your web interface. If the PHP page is on your browser, then everything is working fine, and you are set to proceed further.


Congratulations, you’ve successfully installed and configured Memcached on Ubuntu 18.04. We hope this tutorial was useful. For additional help, we recommend you to visit the official Memcached page.


Check out these top 3 VPS services:

$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$2.95 /mo
Starting price
Visit ScalaHosting
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
Liquid Web
$5.00 /mo
Starting price
Visit Liquid Web
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing

How to Set Up Cron Jobs on Your Ubuntu 18.04 Dedicated Server or VPS

This guide shows webmasters and administrators how to set up cron jobs on your U
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install WordPress on Your Ubuntu 22.04 VPS or Dedicated Server

This tutorial will show you how to install WordPress on your Ubuntu 22.04 virtua
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install a Self-Signed SSL Certificate on Your Ubuntu 18.04 VPS or Dedicated Server

This how-to article will teach you how to create a self-signed SSL certificate o
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Create a Non-root User on Your Ubuntu 18.04 VPS or Dedicated Server

This guide shows you how to create a user on your Ubuntu 18.04 virtual server.
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top