For Ubuntu just add the php5-memcache package and reload apache.

For CentOS,  install the package via PECL. This can be done using the Chef recipes included in the PECL Demo ServerTemplate.

Another option is to create a RightScript that will do this at launch time. The RightScript should contain the following:

#!/bin/bash -ex

# Test for a reboot, if this is a reboot just skip this script.
if test "$RS_REBOOT" = "true" ; then
  echo "Skip install of PECL::Memcache on reboot."
  logger -t InstallPHPMemcacheScript "Skip Example script on reboot."
  exit 0 # Leave with a smile ...

echo "Installing PECL::Memcache"
echo "y" | pecl install -a -f memcache
if [$? -eq '0']; then
  echo "install completed successfully adding to php.conf"
  echo "" > /etc/php.d/memcache.ini

exit 0

Add this RightScript to the boot scripts for your server template and ensure that Apache 2 is restarted after.

See also: