How to Install Memcached on Ubuntu 18.04 & 16.04 LTS

Memcached is a distributed memory object caching system which stored data in memory on key-value basis. It is very useful for optimizing dynamic websites and enabled speed by caching objects in memory. This article will help you to install Memcached with PHP Memcache PECL extension on Ubuntu 18.04, 16.04 and 14.04 systems.

Step 1 – Install Memcached

First of all, update Apt package cache on your system then install Memcached service on your system. Execute below commands from command prompt.

sudo apt-get update
sudo apt-get install memcached

Step 2 – Configure Memcached

You can find the details information about Memcache configuration here. For inital level configuration check for the following settings under Memcache configuration file /etc/memcached.conf.

After making changes, restart the Memcached service.

Step 3 – Verify Memcache Setup

Use the following command to check and verify that Memcached service is running properly on your system. This will show you the current statstics of your Memcached server. So the values may be differ that below results.

pico /etc/memcached.conf


echo "stats settings" | nc localhost 11211
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

Step 4 – Install Memcached PHP Module

Now install latest PHP from ppa:ondrej/php PPA on your Ubuntu system. If you have already installed PHP on your system, just skip PHP installation commands below.

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

Now install PHP Memcached module on your system. The below command will also do the required configuration.

sudo apt-get install -y php-memcached 

After completing the installation, you must restart the Apache service.

sudo service apache2 restart

Check if Memcache php extension is enabled and working properly. Create a info.php file using following code

123<?php  phpinfo();?>

Now access info.php on the web interface and search for Memcache, You will get the result like below.

Install memcached, PHP, Ubuntu
Open POrt 11211 tcp
Untuk uji coba bisa menggunakan script php

source :
Posted on: February 14, 2019, by :