I have installed memcache for a Drupal site with the memcached pecl extension. It's all running fine but I'm still struggling with the configuration settings.

For instance , following advice on drupal.org

You should probably lock down the memcache server so that it only listens for 
connections from the hosts that need to be served, as the default is that 
memcache listens to connections from all addresses. 
So, to close that hole, edit /etc/sysconfig/memcached with:


Problem is that I don't have this file on my server, in any case not at this location. Some other articles have mentioned /etc/memcached.conf but I can't find this file either.

Considering that the /etc/sysconfig/memcached or /etc/memcached.conf do not exit on my server, can I safely create them? Is it possible for these files to be situated somewhere else, in which case where should I look or is there any way to find that info?

Finally , any resources, tutorials or documentation links would be greatly appreciated. I've browsed thru memcache's site Wiki, and could only find a couple of relevant articles for beginners.

  • 1
    The drupal instructions are incorrect. The -l option regulates to which interfaces memcached will listen to, not which hosts will be served. Oct 24, 2016 at 21:32

3 Answers 3


You did not tell us about your OS/distro. Also, you did not tell us how you installed memcached.

Usually, you will get a sample config file under /etc/ when you install memcached using apt-get under debian-based systems and rpm or yum under redhat, fedora or centos.

If you installed it from source, you may not get a sample file under /etc/ (I did not install memcached from source myself). However, you can look for a sample config file in the unpacked source folder.

Anyway, you can use locate memcached.conf to look for one in your system. You need to do sudo updatedb before that to update the search cache.

Here is the config file from my system. You can use it:

# Run memcached as a daemon. This command is implied, and is not needed for the
# daemon to run. See the README.Debian that comes with this package for more
# information.

# Log memcached's output to /var/log/memcached
logfile /var/log/memcached.log

# Be verbose
# -v

# Be even more verbose (print client commands as well)
# -vv

# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-m 64

# Default connection port is 11211
-p 11211
# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
-u memcache

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.

# Limit the number of simultaneous incoming connections. The daemon default is 1024
# -c 1024

# Lock down all paged memory. Consult with the README and homepage before you do this
# -k

# Return error when memory is exhausted (rather than removing items)

# Maximize core file limit
# -r

You can also pass the same options from the command line.

  • Debian GNU/Linux 5.0.9 (lenny) / memcached 1.4.10 .I went thru so many steps in order to install memcache that I can't remember for certain how I did it. It may have been compiled from source since these config files are missing. I know for certain the pecl extensions were installed from source, simply because using pecl didn't work. Looking at the source folder, I couldn't tell what would be the sample config file...
    – PatrickS
    Jan 7, 2012 at 10:57
  • @PatrickS: I updated my answer.
    – Khaled
    Jan 7, 2012 at 11:04
  • I've ended up creating /etc/init.d/memcached using the above command line options to configure memcache
    – PatrickS
    Jan 8, 2012 at 4:48

The default (CentOS) /etc/sysconfig/memcached:


The init script (CentOS) /etc/init.d/memcached:

if [ -f /etc/sysconfig/memcached ];then
        . /etc/sysconfig/memcached

The above amounts to, if the file exists, 'source' it (i.e. read and evaluate its contents).

As far as I know, memcached does not have a configuration file. It uses command line parameters, for example (from a RHEL/CentOS init script):

daemon --pidfile ${pidfile} memcached -d -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -P ${pidfile} $OPTIONS

(You'll note that the variables defined above, are used here).

The bottom line, therefore, is:

  • Check your init script - if it contains a section similar to that above (the if statement) then certainly, create the matching file, and place the appropriate variables in it.
  • There is no configuration file - don't create one as it won't be used.

If you can't find on CentOS /etc/init.d/memcached try this:

nano /usr/lib/systemd/system/memcached.service

and change:

ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS


ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -I $MAXITEMSIZE -c $MAXCONN $OPTIONS

After add in /etc/sysconfig/memcached


Restart memcached

service memcached restart

To check if parameter is added try:

ps aux | grep memcached

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .