Search our database

How To Install memcached And libmemcached

Step 1 – Install memcached from source.

Download the latest source from http://memcached.org/

# cd /usr/src
# wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
# 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 http://libmemcached.org/libMemcached.html

# wget https://launchpad.net/libmemcached/1.0/1.0.17/+download/libmemcached-1.0.17.tar.gz
# 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 127.0.0.1
# vim /etc/rc.d/rc.local
// add this line
/usr/local/bin/memcached -d -u nobody -m 1048 -p 11211 127.0.0.1

 

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
extension=memcache.so

 

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:

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

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

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 @ sales@ipserverone.com