Saturday, June 16, 2012

Installing Memcached on CentOS

I have a web server running CentOS and wanted to get some good caching going for PHP use. This is how I installed memcached, from the command line:

  • Install memcached
    • yum install memcached
  • Install Pecl (if you don't yet have it, installing pear installs pecl)
    • yum install php-pear
  • Install Pecl's Memcached package (for PHP)
    • Install dependencies, as needed
      • yum install php-devel
      • yum install gcc
      • yum install zlib-devel
    • pecl install memcache
    • Use a text editor to add "" to php.ini (may be in the /etc folder)
  • Restart the service
    • service memcached start 
    • service httpd restart
And when you want some raw stats, you can get them via telnet:
  • telnet localhost 11211
And type "stats" to see hits, misses and more!

Here are some examples of memcached use in PHP.