How To Install Memcached with PHP on Ubuntu 14.04 /12.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 14.10, 14.04 and 12.04 systems.

Install Memcached Service

First we recommended to update your system with latest packages.
$ sudo apt-get update
Now use following command to install memcached service on your system.
$ sudo apt-get install memcached

Install PHP with Memcached Support

Now we are going to install php with few more required packages for setup. We also need to install Memcache module for php using below commands.
$ sudo apt-get install php5 php5-dev php-pear php5-memcached

$ sudo apt-get install libmemcached-dev build-essential

Install Memcache PHP Extension

Finally install Memcache php extension using PECL to finish setup.
$ sudo pecl install memcache
Now enable memcache support in php. Before creating a new file just make sure there are no php memcache configuration file available. If file already exists just skip below command.
$ echo "" > /etc/php5/apache2/conf.d/20-memcache.ini
After doing every think just restart your Apache service.
$ sudo service apache2 restart

Verify Memcache Setup

Use following command to check and verify that memcached service is running fine.
root@hackthesec:~$ echo "stats settings" | nc localhost 11211

STAT maxbytes 67108864
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

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

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

About Author:

I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Newer Post
Older Post


Post a Comment