;

How to Setup Memcache on Ubuntu 14

Try it in our public cloud & Get $5 Credit
CLAIM NOW

Memcache is an efficient, RAM-based key-value store that can be deployed as part of a strategy to speed up a site or service. In cases where a given piece of data rarely changes and can be associated with a unique key, Memcache can store the association and quickly return it on demand. In this manner, slow database queries or filesystem accesses can be keyed off of their query content or filename, thus minimizing interaction with the slow system.

Getting Started

To complete this guide, you will need the following:
• 1 Node (Cloud Server or Dedicated Server) running Ubuntu 14.
• A LAMP stack configured
• Root Access to your server

Tutorial

The package for the Memcache daemon is called memcached. We’ll begin by installing this package.

apt-get install memcached -y

In order to integrate Memcache with PHP, we’ll install its extension. This will make the library available for use in any PHP-based applications you may wish to run on this server.

apt-get install php5-memcached

Memcached must now be configured to meet your needs. Edit its configuration.

nano /etc/memcached.conf

The daemon has a variety of switches you can use to tune performance and access. Of particular note is the “-p” switch which sets the daemon’s port. Additionally, “-c” limits the maximum connections allowed, and “-m” sets the amount of RAM allocated to the daemon and its cache.

Having installed the PHP module and configured Memcache, we must restart both Apache and Memcache so the changes are acted upon. We’ll do that now.

service apache2 restart
service memcached restart

In order to integrate with PHP, the memcached module must be loaded. We’ll validate that everything is correctly configured and enabled below.

php -m | grep memcached
memcached

A phpinfo webpage is a great way to evaluate your PHP runtime environment. The phpinfo function prints a variety of diagnostic information about your PHP setup. In this case, it should provide information on the memcached module.

nano /var/www/html/index.php

<?php
phpinfo();
?>

To ensure that everything is set up, visit http://your_ip/index.php. Study the page, looking for details on the memcached module.

Conclusion

Memcache is now installed, configured and running. It is also integrated into your PHP runtime, which is running in the installed Apache web server. Any newly-installed PHP applications can now capitalize on your Memcache installation to provide a fast, reliable caching layer for any slow operations. If this guide was helpful to you, kindly share it with others who may also be interested.