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

Pertandingan Sepak Bola Online Kumpulan Jadwal Pertandingan Bola Online di NOBARTV Click for information

Short-term car insurance is principally with regard to somebody that has handed their own generating check however haven’t selected the actual insurance plan of the option. byersauto.org

This is excellent post. Its having good description regarding this topic. It is informative and helpful. I have known much information from this. Thanks for sharing.Strike Back Seasons 1-3 DVD Box Set | The Best Of Soul Train DVD Box Set | Leverage Seasons 1-5 DVD Box Set | Boston Legal Seasons 1-5 DVD Boxset | Battlestar Galactica Seasons 1-4 DVD Boxset

having good description regarding this topic. It is informative and helpful. Click here

Excellent stuff from you man. I've read your things before and you are just too awesome. I adore what you have got right here. You make it entertaining and you still manage to keep it smart. This is truly a great blog. Thanks for sharing.Thomas and Friends Seasons 1-4 DVD Box Set | Boardwalk Empire Seasons 1-3 DVD Box Set | Project Runway Seasons 12 DVD Box Set | Everybody Hates Chris seasons 1-4 DVD box set | The Mentalist Seasons 1-5 DVD Box set | MI-5 Spooks Seasons 1-9 DVD Box Set

The ad has to be located right in the middle of the page so it could be viewed more than once and people interested could actually proceed to buy the car once they go through the details. www.fitness-als-medizin.com

I almost always use the PECL memcache expansion because I've had some unusual actions in previous times using the memcached extension; likely those issues are set now, but it's become a addiction and individual choice to use the memcache expansion.direct response marketing

Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is great blog. A great read. Agen Ibcbet

Thanks so much with this fantastic new web site. I’m very fired up to show it to anyone. It makes me so satisfied your vast understanding and wisdom have a new channel for trying into the world. Judi Online 88Tangkas

If some one needs to be updated with hottest technologies then he must be pay a quick visit this web page and be up to date everyday. Berita Bola Jadwal Bola Prediksi Bola

That’s why they you need to look after your health and enjoy the great features of insurance plans for a longer period of time the nutrition tips

Another reason for using feature of 'cash on delivery' is that, people in India are not open to share their credit/debit cards details on the internet. Some even do not know how to use it for shopping, even though they are tech savvy. only shopping

You need to understand how the low carb diet plan works before actually adopting it. This will motivate you to follow it even further. In its essence such a nutritional arrangement is supposed to eliminate the major reason for weight gain and to allow for the reverse process to begin.  no carb diet menu

Would you like to know more about Pomeranian Dogs and how Pomeranian dogs work? Read this blog and get to know a Pomeranian puppy more. I'm sure you'll love how a Pomeranian puppy thinks.

Six Figure Funnel Formula is a new marketing product and an internet marketing guide by Todd Brown, check out more about Six Figure Funnel Formula and find out if it's another scam?

This is my first opportunity to chat this website I found some interesting things and I will apply to the development of my blog. I am really impressed by this blog!Very clear explanation of issues is given and it is open to everyone.It contains true and fair information. Your website is very useful. The Simpsons Seasons 1-24 DVD Box Set | Dexter Seasons 1-7 DVD Box Set | House MD Seasons 1-8 DVD Box Set | Walt Disney's 100 Years Of Magic 164 Discs DVD Box set | Curb Your Enthusiasm Seasons 1-8 DVD Box Set | The L Word Seasons 1-6 DVD Box Set

Drupal isolates core files from contributed modules also themes. This increases flexibility further security further acquiesces administrators to cleanly boost to unfamiliar frees lacking overwriting their site's customizations.
voice actor

Despite the popularity of brands hotel chains, the vast number of hotels unrelated to them and act independently.
online punctuation checker

You do know a lot about this. Just out of curiosity. Do u write your own html's or do you use a program like dreamweaver or something? Pakken.

You do know a lot about this. Just out of curiosity. Do u write your own html's or do you use a program like dreamweaver or something? Pakken.

Definitely a great post. Hats off to you! The information that you have provided is very helpful.
http://www.sparkstation.net/

I’m completely enjoying as of it and that I have you ever bookmarked to ascertain out new stuff you'll post.. Can you also check http://www3.nagatogel.com
http://www2.nagatogel.com

Really its a good news.This site has lots of advantage. I found many interesting things from this site. I like it very much. Its so interesting.I want to sharing this topic with some of my close friends. So thanks this post.
http://king88asia.com

Definitely a great post. Hats off to you! The information that you have provided is very helpful.
vegas88.asia

I’m completely enjoying as of it and that I have you ever bookmarked to ascertain out new stuff you'll post.. Can you also check
bokeps

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post
vipbet88.biz

Thanks for taking the time to discuss this, I feel about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.
Hosting Indonesia

This is a very good post. Just wonderful. Truly, I am amazed at what informative things you've told us today. Thanks a million for that.
Togel

I really appreciate the kind of topics post here. Thanks for sharing us a great information that is actually helpful. Good day!
Nagatogel

The you have is very useful. The sites you have referred was good. Thanks for sharing...
Film Porno

You should write about the model/version on the blog. You can expose it's perfect. Your blog examination should widen your readership.I am really grateful for your blog post. I find a lot of approaches after visiting your post. Great work..looking for affordable and trusted hosting?come and visit
Bokep Indo

Thank you for another fantastic posting. Where else could anyone get that kind of information in such a perfect way of writing? I have a speech next week, and I was looking for more info ;)
Bokep Indonesia

king88.asia
Excellent post, I agree with you 100%! I’m always scouring the Internet for new information and learning whatever I can, and in doing so I sometimes leave comments on blogs. I don’t do it for SEO purposes necessarily, but to learn new things.

KONTES SEO
I'm impressed, I must say. Very rarely do I come across a blog that's both informative and entertaining, and let me tell you, you've hit the nail on the head. Your blog is important; the issue is something that not enough people are talking intelligently about.

BOKEP INDO
must say that overall I am really impressed with this blog. It is easy to see that you are passionate about your writing. If only I had your writing ability I look forward to more updates and will be returning.

Very good and interesting blog. I liked your work, I am glad that there are some interesting topics for discussion.

must say that overall I am really impressed with this blog. It is easy to see that you are passionate about your writing. If only I had your writing ability I look forward to more updates and will be returning.

judi bola

taruhan bola

This is a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it

Thank you for another fantastic posting. Where else could anyone get that kind of information in such a perfect way of writing? I have a speech next week, and I was looking for more info ;)

prediksi bola

bolatangkas

The you have is very useful. The sites you have referred was good. Thanks for sharing...

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.