Installation of Memcache in PHP on Ubuntu/Debian

Happy new year all! Just a quick post about how to install Memcache in PHP on an Ubuntu or Debian server (I think it will apply to Redhat based servers, just substitute the apt-get for yum).

Log on to your server as root (either directly or using sudo su), then install the Memcache daemon through apt:

apt-get install memcached

Once installed you need to install the Memcache module into PHP. This is done through PECL which in turn is installed through PEAR. When they are both installed, you need to run the command:

pecl install memcache

This will install the memcache extension, and once done will tell you to add the the line “” into your php.ini file. I prefer keeping these in separate files (so that the php.ini file can be updated). The easy way to do this is:

echo "" > /etc/php5/conf.d/memcache.ini

And finally, reload Apache

/etc/init.d/apache2 reload

If successful, Memcache will now appear in your phpinfo().

5 thoughts on “Installation of Memcache in PHP on Ubuntu/Debian

  1. On Ubuntu 10.10 I did the following:
    1. sudo apt-get install memcached
    2. sudo apt-get install php5-memcache
    3. sudo /etc/init.d/apache2 reload

    This did everything you mentioned above including the memcache.ini file.

  2. Ah yes. I prefer to use the pecl/pear packages where possible as they are kept more up to date than the Ubuntu/Debian repositories.

Leave a Reply