Thursday, May 21, 2015

Ubuntu 14.04 - Memcached server for Wordpress

First thing first: memcache vs memcached

According to http://blackbe.lt/php-memcache-vs-memcached/
PHP has two separate module implementations wrapping the memcached (as in memcache daemon) server.

The memcache module utilizes this daemon directly, whereas the memcached module wraps the libMemcached client library and contains some added bonuses.
Memcached module will be faster than memcache module => I'll go with Memcached module

Install Memcached daemon on my dedicate Memcached host

sudo apt-get install memcached libmemcached-tools

My memcache server listen all of its address. So edit /etc/memcached.conf
-m 20000      #amount of RAM in MB
-p 11211      #listen port 11211
-l 0.0.0.0    #listen on all interfaces

Install memcached client
In other Wordpress PHP server we need to install memcahed client and server (optional):
sudo apt-get install php5-memcached memcached libmemcached-tools php-pear
sudo mkdir /etc/php5/conf.d
ln -s /etc/php5/mods-available/memcached.ini /etc/php5/conf.d/memcached.ini

I need to store Php sessions in Memcached because store in memory will be faster than disk 
Default is session.save_handler = files
Add to /etc/php5/conf.d/memcached.ini
[Session]
session.save_handler = memcached
session.save_path = "tcp://localhost:11211"

Wordpress and Memcached
Finally edit Wordpress wp-config file to add list of Memcached server for Wordpress Total cache plugin
global $memcached_servers;
$memcached_servers = array('default' => array('192.1.3.30:11211','192.1.1.11:11211','192.1.1.12:11211'));

Now your Wordpress can Memcached it.

0 comments:

Post a Comment