Memcached overview

This article contains information/examples about root/sudo/admin users. These commands can only be ran on a Dedicated server with an admin user.

Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. Many web applications (MediaWiki, Drupal, and so on) offer support for memcached.

Danga Interactive developed memcached to enhance the speed of LiveJournal.com, a site which was already doing 20 million+ dynamic page views per day for 1 million users with numerous webservers and database servers. Memcached dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization, and faster access to the databases on a memcache miss.

memcached is only available on a Dedicated hosting plan.

(1) Installing the memcached server daemon

  1. Log into your server via SSH. Make sure you log into the server using an admin user on the Dedicated server.
  2. Run the following command to change to the root user:
    [server]$ sudo su
  3. Run the following to install the memcached daemon (server-based) package:
    [server]$ apt-get install memcached
  4. After installing the memcached daemon, download a client package to access the server and extend PHP to connect to your memcached daemon.

(2) Install the libmemcache library

  1. Review the memcached installation documentation at php.net.
  2. Make sure you're in your admin user's $HOME directory. 
    [server]$ cd $HOME
  3. Obtain the prerequisite libmemcache at https://launchpad.net/libmemcached
    [server]$ wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
    [server]$ tar -zxvf libmemcached-1.0.18.tar.gz
    [server]$ cd libmemcached-1.0.18
    [server]$ ./configure
    [server]$ make
    [server]$ make install
    

(3) Install PECL’s memcache client

To use the PECL memcache client:

  1. Make sure you're in your admin user's $HOME directory. 
    [server]$ cd $HOME
  2. Download the source code and compile it:
    [server]$ wget http://pecl.php.net/get/memcache-2.2.7.tgz
    [server]$ tar -zxvf memcache-2.2.7.tgz
    [server]$ cd memcache-2.2.7
    
  3. Compile for PHP 5.6 (assuming you're using this version):
    [server]$ /usr/local/php56/bin/phpize
    [server]$ ./configure --with-php-config=/usr/local/php56/bin/php-config
    [server]$ make
    [server]$ make install
    
    • The ‘make install’ command ends with the following response:
    Installing shared extensions:     /usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226/
  4. After the shared object is compiled, add it to your PHP configuration.

    For further information on adding a phprc file under the user your domain runs on, visit the following page:

  5. Add the following line to that phprc file:
    extension = “/usr/local/php56/lib/php/extensions/no-debug-non-zts-20100525/memcache.so”
    
  6. Kill off all running PHP processes. For further information, visit the following page:
  7. Check your PHP configuration in a phpinfo.php file to confirm the extension is loading. For further information, visit the following page:
    01 memcached.png

See also