is a system based on RAM. This means you can generate caches on the fastest way, instead of hard cache, RAM cache is way faster and allows almost any kind of app integration with the most modern programming languages such as python, , ruby, etc. On this tutorial I will assume you are using Linux, RHEL or Fedora. I will cover both memcached system daemon and the 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  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 to apply changes:

If you use php-fpm:

service php-fpm reload 

If you use apache:

service  reload

Test your PHP Memcached module:

php -i | grep memcache -i

Should output something like this:

[[email protected] ~]# 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:

[[email protected] ~]# 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

Print Friendly, PDF & Email



Bài viết liên quan