Search our database

How To Install memcached And libmemcached

Step 1 – Install memcached from source.

Download the latest source from

# cd /usr/src
# wget
# tar xvf memcached-1.4.15.tar.gz
# cd memcached-1.4.15
# ./configure -–with-libevent
# make && make install

Please ensure libevent & libevent-devel packages have been installed before executing the command above.


Step 2 – Install libmemcached from source.

Download the latest source from

# wget
# tar xvf libmemcached-1.0.17.tar.gz
# cd libmemcached-1.0.17
# ./configure
# make && make install


Step 3 – Start the memcached as daemon process and ensure memcached is automatically started after each server reboot.

# memcached -d -u nobody -m 1048 -p 11211
# vim /etc/rc.d/rc.local
// add this line
/usr/local/bin/memcached -d -u nobody -m 1048 -p 11211


Step 4 – Install the Memcache PECL Extension for PHP.

# pecl install memcache


Add the following codes into php.ini

# vim /usr/local/lib/php.ini
// add this line


Restart the httpd service.

# /etc/init.d/httpd restart


Step 5 – Verify the memcached using php and libmemcached. Create a new .php file and add the following codes:

    $memcache = new Memcache;
    $memcache--->connect("localhost",11211); # You might need to set "localhost" to ""

    echo "Server's version: " . $memcache-&gt;getVersion() . "
    $tmp_object = new stdClass;
    $tmp_object-&gt;str_attr = "test";
    $tmp_object-&gt;int_attr = 123;
    echo "Store data in the cache (data will expire in 10 seconds)
    echo "Data from the cache:

or else, run

# strace -p `pidof memcached`


Windows Dedicated Server from RM549/mth!

Check out IPServerOne’s Dedicated Server Packages.
Contact us @ +603-6259-5625 or email @