Ubuntu – Setting up memcached/memcache with Php on Ubuntu 10.10

memcachememcachedPHPUbuntuubuntu-10.10

I'm assuming memcache and memcached are two completely different things, and that I want to use memcached.

I have two separate servers (one is a webserver, one is meant for the db). I don't know which one would be better to keep memcached on.

Can someone explain to me the differences between memcached/memcache and the easiest way to install what is necessary? I keep seeing this libmemcached thing I'm supposed to download and compile or something? Seems like someone would have a working package for this sort of thing.

I'm using php, so php needs to be able to interact w/ it.

Best Answer

Memcached is the name of the Memcache daemon.

Using Memcache with PHP you are able to store PHP sessions in memory rather than in separate files on disk. This results in many times faster session management. This is especially useful when you've set up a load balancer and a few web app servers behind it but you plan to share sessions for each of your servers. You can run memcache on one of your servers or a separate server and make all your servers cache to the one running Memcache.

To get started:

sudo apt-get install memcached

Go through the config file in /etc/memcached/memcached.conf and see if the defaults are good for you.

Now install php's memcache client

sudo apt-get install php5-memcache

When asked, enable session handler support. Also, add

extension=memcache.so

and

session.save_handler = memcache
session.save_path = "tcp://10.0.0.1:11211"

to your php.ini (probably in /etc/php5/apache2/php.ini). Change the ip to your memcache server address or to 127.0.0.1 if you run it locally.

Start the service with

/etc/init.d/memcached start

Before installing anything, you really should read up on what the package does otherwise you will not be able to get the most out of it.