Tuesday 22 February 2011

memcached on drupal 6

environment: ubuntu hardy (8.04), drupal 6.13

memcached

To install memcached, you need to install libevent first:
sudo apt-get install libevent-dev
Install memcached:
mkdir src
cd src
wget http://memcached.googlecode.com/files/memcached-1.4.0.tar.gz
tar xzvf memcached-1.4.0.tar.gz
cd memcached-1.4.0
./configure
make
sudo make install
cd ..
Create control script:
sudo nano /usr/local/bin/memcache.sh
Add the following code:
#!/bin/sh
case "$1" in
start) /usr/local/bin/memcached -d -u root -m 240  -p 11211
;;
stop)  killall memcached
;;
esac
240 is the memory limit for the instance of memcached, the unit is MB.
11211 is the port number.
make it executable :
sudo chmod +x /usr/local/bin/memcache.sh 
start a memcached instance when the server startup:
sudo nano /etc/rc.local
add:
/usr/local/bin/memcache.sh start
start a memcached instance by running:
/usr/local/bin/memcache.sh start

PECL memcache extension for PHP

install php-pear if you have not installed it yet
apt-get install php-pear
install PECL memcache :
pecl install Memcache 
Edit the php.ini
nano/etc/php5/fpm  php.ini file:
add "extension=memcache.so" to it.

Restart nginx and php5-fmp


Memcache API and Integration module

open settings.php of your drupal site ( /sites/default/settings.php ), and add the following to the end of the file :
$conf = array(
   'cache_inc' => './sites/all/modules/memcache/memcache.inc',
 );
note: you may place './sites/all/modules/memcache/memcache.inc' with 'cache_inc' => './sites/all/modules/memcache/memcache.db.inc' to cache data both to memory and database if your memcache's memory limit is small or the memcached instance go offline often. (See the README.txt of Memcache API and Integration for more details. )
download Memcache API and Integration module from http://drupal.org/project/memcache, install and enable it.
Now, the integration of memcached and your drupal site is done. You can view memcache status from /admin/reports/memcache .

source

No comments:

Post a Comment