How to install memcached on openSUSE for use with Drupal

This guide is based on various community forum posts.

This guide is intended as a relatively easy step by step guide to:

  • Install and configure memcached and memcache PHP extension on openSuSE 11.1 and higher for use with Drupal and the Drupal Memcache module.
  • This is a very basic single memcached server setup but a good starting point for getting memcached working. 

Requirements:

  • openSUSE 11 or later installed on your machine. 
  • PHP 5.2.0 or higher installed

 


1. Install memcached on your server.

  • Open the Terminal Window and enter :
yast2 -i memcached

2. Install memcache PHP extension using PECL.

pecl install memcache

3. Add memcache.so to php.ini

  • We must instruct PHP to load the extension.
  • You can do this by adding a file named memcache.ini to the configuration directory /etc/php5/conf.d
  • Open the Terminal Window and enter :
vi /etc/php5/conf.d/memcache.ini
  • Add the following line to the file and save :
extension=memcache.so
  • If you intend to use memcached with Drupal also add the following line to your php.ini or memcache.ini file and save :
memcache.hash_strategy="consistent"

4. Add memcached to system startup.

  • Open the Terminal Window and enter :
chkconfig --add memcached

5. Open firewall port 11211.

  • The default port for the memcached server is TCP port 11211.
  • Configure your firewall to open port 11211 for TCP traffic.
  • Tip : Use YAST to cofigure your firewall if you are using SUSEFirewall2

6. Configure the memcached allowed memory.

  • All memcached configuration settings can be found in /etc/sysconfig/memcached
  • The default memory setting for memcached is 64 MB. 
  • Depending on the amount of RAM available on the server allocate a block of memory to memcached.
  • Open the Terminal Window and enter :
vi /etc/sysconfig/memcached
  • Change the following line FROM-
MEMCACHED_PARAMS="-d -l 127.0.0.1"
  • TO the following by adding the -m 4096 bit to allow memcached 4 GB of RAM. Adjust the size in MB according to the memory that you have available. Save the file when done.
MEMCACHED_PARAMS="-m 4096 -d -l 127.0.0.1"

7. Start the memcached service.

  • Open the Terminal Window and enter :
service memcached start

8. Restart Apache.

  • Open the Terminal Window and enter :
service apache2 restart

9. Check to see if memcached server is active and listening on port 11211.

  • Open the Terminal Window and enter :
netstat -tap | grep memcached

10. Check the status and stats with memcached-tool

  • Part of the memcached package is a handy tool called memcached-tool.
  • You need to specify the host IP and port. In this case the host IP is 127.0.0.1 and the port 1211.
  • Open the Terminal Window and enter :
memcached-tool 127.0.0.1:11211 stats

11. Activate the Drupal memcached module.

  • Install the Drupal Memcache module and activate. For more complete instructions visit the Drupal Memcache Documentation
  • Edit settings.php in your Drupal installation to include memcache.inc
  • For Drupal 6, edit the settings.php file and add the following :
$conf['cache_inc'] ='sites/all/modules/memcache/memcache.inc';
  • For Drupal 7, edit the settings.php file and add the following :
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['memcache_key_prefix'] = 'something_unique';

* note : Replace the "something_unique" in the last line with your own unique memcache key prefix.

Tags: