Memcached and PECL memcache on CentOS and Fedora

At Tag1 Consulting we do a lot of work on increasing web site performance, especially around Drupal sites. One of the common tools we use is memcached combined with the Drupal Memcache module. In Drupal, there are a number of different caches which are stored in the (typically MySQL) database by default. This is good for performance as it cuts down on potentially large/slow SQL queries and PHP execution needed to display content on a site. The Drupal Memcache module allows you to configure some or all of those caches to be stored in memcached instead of MySQL, typically these cache gets/puts in memcache are much faster than they would be in MySQL, and at the same time it decreases work load on the database server. This is all great for performance, but it involves setting up an additional service (memcached) as well as adding a PHP extension in order to communicate with memcached. I've seen a number of guides on how to install these things on Fedora or CentOS, but so many of them are out-dated or give instructions which I wouldn't suggest such as building things from source, installing with the 'pecl' command (not great on a package based system), or using various external yum repositories (some of which don't mix well with the standard repos). What follows is my suggested method for installing these needed dependencies in order to use memcached with Drupal, though the same process should be valid for any other PHP script using memcache.

PECL Packages

For the Drupal Memcache module, either the PECL memcache or PECL memcached (note the 'd'!) extensions can be used. While PECL memcached is newer and has some additional features, PECL memcache (no 'd'!) tends to be better tested and supported, at least for the Drupal Memcache module. Yes, the PECL extension names are HORRIBLE and very confusing to newcomers! I almost always use the PECL memcache extension because I've had some strange behavior in the past using the memcached extension; likely those problems are fixed now, but it's become a habit and personal preference to use the memcache extension.

Installing and Configuring memcached

The first step is to get memcached installed and configured. CentOS 5 and 6 both include memcached in the base package repo, as do all recent Fedora releases. To install memcached is simply a matter of:
# yum install memcached

Generally, unless you really know what you're doing, the only configuration option you'll need to change is the amount of memory to allocate to memcached. The default is 64MB. That may be enough for small sites, but for larger sites you will likely be using multiple gigabytes. It's hard to recommend a standard size to use as it will vary by a large amount based on the site. If you have a "big" site, I'd say start at 512MB or 1GB; if you have a smaller site you might leave the default, or just bump it to 512MB anyway if you have plenty of RAM on the server. Once it's running, you can watch the memory usage and look for evictions (removal of a cache item once the cache is full) to see if you might want to increase the memory allocation.

On all Fedora / CentOS memcached packages, the configuration file is stored in /etc/sysconfig/memcached. By default, it looks like this:

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

To increase the memory allocation, adjust the CACHESIZE setting to the number of MB you want memcached to use.

If you are running memcached locally on your web server (and only have one web server), then I strongly recommend you also add an option for memcached to listen only on your loopback interface (localhost). Whether or not you make that change, please consider locking down the memcached port(s) with a firewall. In order to listen only on the 127.0.0.1 interface, you can change the OPTIONS line to the following:

OPTIONS="-l 127.0.0.1"

See the memcached man page for more info on that or any other settings.

Once you have installed memcached and updated the configuration, you can start it up and configure it to start on boot:

# service memcached start
# chkconfig memcached on

CentOS / RHEL PECL Module Install

Fedora

If you are on Fedora and using PHP from the base repo in the distribution, then installation of the PECL extension is easy. Just use yum to install whichever PECL extension you choose:

# yum install php-pecl-memcache

Or

# yum install php-pecl-memcached

CentOS 5 / RHEL 5

CentOS and RHEL can be a bit more complicated, especially on EL5 which ships with PHP 5.1.x, which is too old for most people. Here are the options I'd suggest for EL5:

  • If you are OK using the PHP provided with EL5, then you can get the PECL extensions from EPEL. Once you've enabled the EPEL repository (instructions), you can install either PECL extension by using the same yum commands outlined above in the Fedora section.
  • If you want to use PHP 5.2 or PHP 5.3 with EL5, I suggest using the IUS repositories (IUS repo instructions). Note that IUS provides the PECL memcache extension, but not the PECL memcached extension. Based on which PHP version you decide to use, you can install the PECL memcache extension with either:

    # yum install php52-pecl-memcache

    Or

    # yum install php53u-pecl-memcache

CentOS 6 / RHEL 6

EL6 ships with PHP 5.3, though it is an older version than is available for EL6 at IUS. If you are using the OS-provided PHP package, then you can install the PECL memcache extension from the base OS repo. If you want the PECL memcached extension, it is not in the base OS repo, but is available in EPEL. See the instructions linked from the CentOS 5 section above if you need to enable the EPEL repo.

# yum install php-pecl-memcache

Or, enable EPEL and then run:

# yum install php-pecl-memcached

As with EL5, some people running EL6 will also want the latest PHP packages and can get them from the IUS repositories. If you are running PHP from IUS under EL6, then you can install the PECL memcache extension with:

# yum install php53u-pecl-memcache

Similar to EL5, the IUS repo for EL6 does not include the PECL memcached module.

PECL Memcache Configuration

If you are using PECL memcache extension and will be using the clustering option of the Drupal Memcache module which utilizes multiple memcached instances, then it is important to set the hash strategy to "consistent" in the memcache extension configuration. Edit /etc/php.d/memcache.ini and set (or un-comment) the following line:

memcache.hash_strategy=consistent

If you are using the PECL memcached module, this configuration is done at the application level (e.g. in your Drupal settings.php).

Once you've installed the PECL memcache (or memcached) extension, you will need to reload httpd in order for PHP to see the new extension. You'll also need to reload httpd whenever you change the memcache.ini configuration file.

# service httpd reload

SELinux

If you have SELinux enabled (you should!), I have an older blog post with instructions on configuring SELinux for Drupal.

That's it, you're now good to go with PHP and memcache!

Comments

Helped a lot thanks

Jadwal Nonton TV Bola Online Jadwal Nonton TV Berita Bola Online di NOBARTV
Berita Sepak Bola Online Terkini berita bola terbaru di NOBARTV
Kumpulan Jadwal Pertandingan Sepak Bola Online Kumpulan Jadwal Pertandingan Bola Online di NOBARTV
Kumpulan Kabar Harian Berita Sepak Bola Online Kumpulan Berita Bola Online di NOBARTV

Online Terkini berita bola terbaru di NOBARTV
Kumpulan Jadwal Pertandingan Sepak Bola Online Kumpulan Jadwal Pertandingan Bola Online di NOBARTV Anime Filme

Kumpulan Jadwal Pertandingan Sepak Bola Online Kumpulan Jadwal Pertandingan Bola Online di NOBARTV Bromo Tengger Semeru

Jadwal Pertandingan Sepak Bola Online Kumpulan Jadwal Pertandingan Bola Online di NOBARTV Internetbureau Haarlem

Jadwal Pertandingan Sepak Bola Online Kumpulan Jadwal Pertandingan Bola Online di NOBARTV Agen bola terpercaya

This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this. rowing machine reviews

It is not everyday that I have the possibility to see something like this.Cars On Terms

This article is really the best. So, I would like you that you keep on continuing your work on this article. And upload as many new articles about this as possible. i need him to fall in love with me

Kami Toko mebel jepara jual mebel harga murah asli Mebel Jati yang tentunya dengan kualitas terbaik dan khas dengan ukiran mebel Tempat Tidur katalog produk mebel kami banyak dan lebih dari ratusan hingga ribuan produk yang bisa anda cek disini Kamar Set dengan harga yang relatif murah anda sudah bisa mendapatkan produk Kamar Set Minimalis asli produk jati dari jepara, juga tersedia produk Gebyok Jepara yang sangat cantik dan khas dengan ukirannya, banyak juga produk produk untuk ruang tamu rumah anda berupa Kursi Tamu dengan desain minimalis ataupun klasik, semuanya kami tawarkan dengan harga yang cukup terjangkau Meja Makan salah satu produk utama yang harus ada dalam satu hunia rumah kami sediakan dengan berbagai macam model Kursi Tamu Minimalis sampai dengan model yang mewah yang tentunya kemewahan dari produk kami beda dengan yang lain Kursi Tamu Mewah model meja makan minimalis ada banyak di katalog website kami, anda bisa mengeceknya di sini Meja Makan Jati produk modern berbahan baku jati yang tentunya sangat awet untuk anda peroleh untuk ditempatkan di rumah anda, semua itu anda bisa melihatnya di katalog produk Mebel Minimalis untuk mebel jati memang sudah tidak asing lagi kalau kualitas mebel jati yang bagusa hanya dari Mebel Jati Jepara untuk semua produk yang kami tawarkan semuanya kami tawarkan produk tersebut dengan harga Mebel Jepara Murah

for installing these needed dependencies in order to use memcached with Old School New Body book

The new talent system makes every decision difficult.
Buy High PageRank BackLinks

This is some real bad ass article, my man! One of the most hi-fi article that I've ever read is surely this one. I am real pleased by this and hope that you will continue to contribute in the same way in the coming weeks as well. kontorimööbel

Most of the time I don’t make comments on but I'd like to say that this article really forced me to do so. Really nice post! more techniques on rebelmouse

The Ponte City photo essay speaks in a similar voice. As with the prison series, it stresses the space that controls the movements and choices of the individual – recalling Michel Foucault’s meditations on space, power and control.Charter Communications Login

I've had some strange behavior in the past using the memcached extension; likely those problems are fixed now, but it's become a habit and personal preference to use the memcache extension.http://www.super6.me/365bet.html

I am having a good day today. I am reading the world's best article right now, soon I will be going to my farm house to enjoy! building chicken coops

You may post on the professional credentials for the blog owner. You could express it's outstanding. Your blog experience can springboard your click through. http://vivitranslation.com/about-us/china-business-etiquette-culture.html

It's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information. http://kbdc.org

I don't have time to go through it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the awesome job. http://www.muddybuddies.com

If you have a business in Yorkshire and would appreciate extra paying customers, extra sales and greater profits, we would love to carry out SEO for you. Give us chance. We want to make your business more of a success. http://www.perfect4tography.com/trick-photography-and-special-effects-re...

This is really good information I have visited this blog to read something fresh and I really admire you efforts in doing so. http://www.donnaglamour.it

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. http://www.invoicefunders.co.nz/

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more. https://google.com/+ContainerbasisDe

Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site. Artists

It's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information. http://www.floorsandchores.net

I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. http://hackps.com

There are various motives that you would would like to buy Instagram followers. We offer actual followers so they're authentic people today looking at your posts, not bots or phony followers. This can place your pictures and video clips in front of a huge number of viewers who will likes and comment. This normally produces a snowball effect allowing for lots of our consumers to go viral. http://www.getigpromotion.com/buy-instagram-comments/

This is very useful post for me. This will absolutely going to help me in my project. http://leapforwardinc.com/

Thanks Fiona - good point. For most of us, orienting our lives towards love is a huge change. However, once it takes hold, the economic problems usually fade into the background. I'll reflect on that for the next book http://www.howtolosethighfat.org

AAPIs who are linguistically isolated may be less likely to seek help if they have a medical concern. To help reduce these disparities, nurses who serve AAPI communities should know about available multilingual online resources. EvoWPThemes

I, along with my partner here, were just wondering if you could tell us the source of the place where you get this all important information from. https://www.rebelmouse.com/breakupcurereviews/

This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this. waffle maker

This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this. noise cancelling headphones review

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. cursos gratis para desempleados

This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this. health product reviews

This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this. Sperian Biosystems

Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog. raleigh search engine optimization http://raleighseo.marketing1on1.com/

This extract is made from the Tamarind tree and is completely natural. It is also known for weight loss. People have been using this extract for centuries and it has been proven at successfully helping people lose weight. http://www.mypbxdubai.com

I'm tossing it (too late to return it to Amazon). This has a lot of great attributes to it, especially for the price (the biggest selling point IMO), but it does have a lot of sugars in it and the protein is a mix of time released protein as opposed to straight whey. Not worth keeping, sending all back. This is much better! Trying to avoid surgery for as long as I can farby palette blond

A very great idea to share all the details like pictures and whereabouts. The idea is new and very good. playstation

What follows is my suggested method for installing these needed dependencies in order to use memcached with Drupal, though the same process should be valid for any other PHP script using memcache.http://delong.typepad.com/sdj/2014/05/morning-must-read-christian-broda-and-jonathan-a-parker-the-economic-stimulus-payments-of-2008-and-the-aggregate-demand-fo.html

This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this. http://www.gfsprague.com/gutters/

I'm now not sure the place you are getting your information, but good topic. I must spend a while finding out more or understanding more. Thank you for fantastic information I used to be searching for this info for my mission. http://www.newcase.com.au/iphone-4-4s-leather-wallet-case-blue/

with the standard repos). What follows is my suggested method for installing these needed dependencies in order to use memcached with Drupal, though the same process should be valid for any other PHP script using memcache.calgary mortgage broker

Its opportunity are so fantastic and working style so speedy - See more at: http://www.youmedia.org/resources#sthash.MVSaM8GV.dpuf
sustanon for sale

Its opportunity are so fantastic and working style so speedy ..
sustanon for sale

Most of the time I don't make comments on websites, but I'd like to say that this article really forced me to do so. Really nice post. kimberly clark products catalog

This is so cool. I am such a huge fan of their work. I really am impressed with how much you have worked to make this website so enjoyable. benicar lawyer attorney

If you are using the PECL memcached module, this configuration is done at the application level (e.g. in your Drupal settings.php). official site

Pages

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.