Install Memcached And PHP5-MemCached Module On Debian 6.0 (Squeeze)

Want to support HowtoForge? Become a subscriber!
 
Submitted by anthony.zhan (Contact Author) (Forums) on Fri, 2011-11-25 17:23. :: Debian | Web Server | Apache | PHP

Install Memcached And PHP5-MemCached Module On Debian 6.0 (Squeeze)

"Memcached is free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load."
More information about memcached can be found at http://www.memcached.org/

This article is going to explain how to install memcached and PHP5-MemCached module on a Debian 6.0(Squeeze) system with Apache2.

 

1. Installing

apt-get install memcached php5-memcached

"apt-get" is a very powerful command-line tool for handling packages. Here is a tip about how to use "apt-get", take this situation as an example: I'm going to install Memcached and php module associated with it, but I'm not quite sure about the exact name of the packages, then we can use the following command to search the available package lists:

apt-cache search memcache

Then you will find something like this:

memcached - A high-performance memory object caching system
memcachedb - Persistent storage engine using the memcache protocol
......
php5-memcache - memcache extension module for PHP5
php5-memcached - memcached extension module for PHP5

You should find both php5-memcache and php5-memcached, php5-memcached is newer and has sessions support. Here I'm going to use php5-memcached.

 

2. Testing

2.1 Testing Memcached

After the installation, memcached should already be running. You can have a check by using the following command:

netstat -tap | grep memcached

Usually you will get something like this:

tcp 0 0 localhost:11211 *:* LISTEN 2132/memcached

You can change its configuration by modifying the file /etc/memcached.conf.

 

2.2 Testing PHP5-Memcached Module

First you need restart Apache web server,

/etc/init.d/apache2 restart

Create a php file which accessible from web and copy the content to the file:

vi phpinfo.php

<?
php phpinfo();
?>

Then use browser to open the php file to check result.

 

3. Using

For more detail please check http://www.php.net/manual/en/book.memcached.php, here is a simple example:

<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$m->set('key', 'hello world');
var_dump($m->get('key'));
?>

 

4. Links

PHP-MemCached Module
MemCached


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anthony (not registered) on Tue, 2012-12-11 21:44.
Great article, installing memcached was easy with this tutorial.
Submitted by Anonymous (not registered) on Tue, 2012-05-29 19:37.

Link to PHP-MemCached Module is broken.