Tips / Nginx

How to install Memcached on CentOS


Memcached is a cache system based on RAM. This means you can generate caches on the fastest way, instead of hard disk cache, RAM cache is way faster and allows almost any kind of app integration with the most modern programming languages such as python, php, ruby, etc. On this tutorial I will assume you are using CentOs Linux, RHEL or Fedora. I will cover both memcached system daemon and the PHP memcache module installation. Let’s start.

Memcached requirements

Grab some developer tools and some php packages which we will use later for memcache PHP installation

yum groupinstall "Development Tools"
yum install php php-pear php-devel

Ensure your system is up to date

yum update

Install memcached on CentOS

yum install memcached

Configuring memcached

nano -w /etc/sysconfig/memcached

Ensure the config stays as you see below:


PORT 11211 is the default port memcached is listening.
USER is the system user memcached will run as.
MAXCONN are the maximum possible connections.
CACHESIZE in MB, in this case 64 MB of cache, unless you have tons of traffic, this is good for most small/medium websites.
OPTIONS -l means this will listening only on the localhost, avoiding any external connections.

Start Memcached

service memcached start

Add memcached to your boot system

chkconfig memcached on

Install Memcached PHP extension

pecl install memcache

If your PECL installer ask you the question you see below, just type enter.

"Enable memcache session handler support? [yes]"

Add module to php.ini

echo "" >> /etc/php.ini

Reload your php server to apply changes:

If you use php-fpm:

service php-fpm reload 

If you use apache:

service httpd reload

Test your PHP Memcached module:

php -i | grep memcache -i

Should output something like this:

[root@localhost ~]# php -i | grep memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20

Test memcached system daemon

ps -aux | grep memcached

If memcached is ok you should see something like this:

[root@localhost ~]# ps -aux | grep memcached
memcach+  8355  0.0  0.0 314816  1100 ?        Ssl  09:25   0:00 /usr/bin/memcached -u memcached -p 11211 -m 64 -c 1024

Popular search terms:

  • https://www scalescale com/tips/nginx/install-memcached-centos/
  • centos installed memcached error ERR_TOO_MANY_REDIRECTS
  • install memcached centos
  • memcached daemon

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Yazir Arafath

    ps -aux | grep memcached

    Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
    497 12348 0.0 0.0 330844 880 ? Ssl 14:31 0:00 memcached -d -p 11211 -u memcached -m 256 -c 1024 -P /var/run/memcached/ -l
    root 14943 0.0 0.0 103316 852 pts/1 S+ 14:35 0:00 grep memcached

    ps aux | grep memcached
    497 12348 0.0 0.0 330844 880 ? Ssl 14:31 0:00 memcached -d -p 11211 -u memcached -m 256 -c 1024 -P /var/run/memcached/ -l
    root 14943 0.0 0.0 103316 852 pts/1 S+ 14:35 0:00 grep memcached

    Is memcached running on my server?

  • thx. worked great.