How To Install Memcached with PHP on CentOS/RHEL 7/6/5

Memcached is a distributed memory object caching system which stored data in memory on key-value basis. It is very useful for optimizing dynamic websites and enabled speed by caching objects in memory. Read more about memcache.

Read Article:
How to Set Up phpMemcachedAdmin on Linux
How To Install Memcached with PHP on Ubuntu 14.04 /12.04 LTS

This article will help you to install Memcached and PHP Memcache extension on CentOS/RHEL 7/6/5 systems.

Install Memcached Server

First we will install Memcached server on our system. Use following command to install memcached using yum package manager.
# yum install memcached
Now start Memcached service using following commands.
For CentOS/RHEL 7
# systemctl enable memcached
# systemctl start memcached

For CentOS/RHEL 6/5
# service memcached start
# chkconfig memcached on

Install PHP with Memcache PHP Extension

Now we have installed Memcached server on our system. But to use Memcached service using php scripts we need to install Memcache php extension. So first install php and other required php modules and then use PECL to install PHP Memcache extension using following commands.
# yum groupinstall "Development tools"
# yum install zlib zlib-devel
# yum install php php-devel php-pear
After installing php-pear package install PECL extension using command below.
# pecl install memcache
Now we need to enable memcache module in php. Add following line at end of php.inifile.
# echo "extension=memcache.so" >> /etc/php.d/memcache.ini
Restart Apache service to enable extension
For CentOS/RHEL 7
# systemctl restart httpd

For CentOS/RHEL 6/5
# service httpd restart

Verify Memcache Setup

Use following command to check and verify that memcached service is running fine.
rahul@tecadmin:~$ echo "stats settings" | nc localhost 11211

STAT maxbytes 67108864
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter 127.0.0.1
STAT verbosity 0
STAT oldest 0
STAT evictions on
STAT domain_socket NULL
STAT umask 700
STAT growth_factor 1.25
STAT chunk_size 48
STAT num_threads 4
STAT num_threads_per_udp 4
STAT stat_key_prefix :
STAT detail_enabled no
STAT reqs_per_event 20
STAT cas_enabled yes
STAT tcp_backlog 1024
STAT binding_protocol auto-negotiate
STAT auth_enabled_sasl no
STAT item_size_max 1048576
STAT maxconns_fast no
STAT hashpower_init 0
STAT slab_reassign no
STAT slab_automove 0
END

Now check if memcache php extension is enabled and working properly. Create a info.php file using following code
<?php
  phpinfo();
?>
Now access info.php on web interface and search for Memcache, You will get result like below.

Comments

Popular Posts