Instructions to install Memcached on CentOS

zwol

New member
Registered
Joined
Apr 21, 2016
Messages
4
Points
0
Memcached is a cache system which works by temporarily storing information or data in RAM. Due to the speed of read-write memory always being faster than reading files from the hard drive or even solid state drive, the memcached stored files should help speed up your system considerably.

Models of Memcached operations:

instructions-to-install-memcached-on-CentOS.jpg

In this article, I will guide you how to install Memcached on CentOS 7/6/5.

Install Memcached

- Install repository for CentOS 5 Remi (CentOS 7 and 6 do not need this step)

Code:
Dependency on CentOS 5 ## Remi
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
- Install Memcached package

Code:
## CentOS 7 and 6
yum install memcached
## CentOS 5
yum install memcached --enablerepo = remi
You should note that there are two package memcache and memcached (with and without the d at the end) and there are 2 versions of the PHP Extension Module php-pecl respectively, memcache and php-pecl-memcached. We will use version 2 (with the letter d) because it is stable and supports more functions.

Configure Memcached

The most important parameters to keep in mind is that Cachesize unit is MB. For example, below I used to 128MB cache (default 64MB)

Code:
nano / etc / sysconfig / memcached
PORT = "11211"
USER = "memcached"
Maxconn = "1024"
CacheSize = "128"
OPTIONS = ""
Booting Memcached

Code:
chkconfig memcached on
memcached service start
Check that Memcached is running

Code:
memcached-tool 127.0.0.1:11211 stats
# 127.0.0.1: 11211 Field Value
accepting_conns 1
auth_cmds 0
auth_errors 0
bytes 0
bytes_read 14
bytes_written 768
cas_badval 0
cas_hits 0
cas_misses 0
cmd_flush 0
cmd_get 0
cmd_set 0
conn_yields 0
connection_structures 11
curr_connections 10
curr_items 0
decr_hits 0
decr_misses 0
delete_hits 0
delete_misses 0
evictions 0
get_hits 0
get_misses 0
incr_hits 0
incr_misses 0
limit_maxbytes 536870912
listen_disabled_num 0
pid 1232
pointer_size 64
rusage_system 0.000999
rusage_user 0.000000
4 threads
time 1402941264
total_connections 12
TOTAL_ITEMS 0
uptime 114
version 1.4.4
Note uptime” parameter at the bottom, which means memcached is running already.
Also you can use phpMemcachedAdmin to see right on your browser.

Memcached open port (11211) on iptables firewall

If memcached is installed somewhere other than the local machine, you will need to make sure it has access through your iptables firewall.

Use the following command
Code:
iptables -A INPUT -m state -m tcp -p tcp --ctstate NEW -j ACCEPT --dport 11211
Restart iptables firewall
Code:
service iptables restart

Installing Memcached and Memcache PHP Module on CentOS

For Memcached to work with PHP, we need to install the PHP module.

PHP 5.5
Code:
yum --enablerepo = remi, remi-install php-pecl-php55 php-pecl-memcache memcached
PHP 5.6
Code:
yum --enablerepo = remi, remi-install php-pecl-php56 php-pecl-memcache memcached
Finally launch PHP and web server
Code:
php-fpm service restart
nginx service restart
Install Memcached with WordPress

To use Memcached with WordPress, you should install the plugin W3 Total Cache”.

instructions-to-install-memcached-on-CentOS2.jpg

In the plugin settings, select the caching method as Memcached cache page for the module Page Cache and Object Database Cache.
Now, let's enjoy the speed that Memcached provides.

Good luck!
 

Chris Worner

Well-known member
Registered
Joined
Apr 15, 2016
Messages
612
Points
28
Thanks for great article!

I am using Wordpress, I want to make my wordpress site work with Memcached. How to enable memcached on wordpress.

Are there any tools/ways to do this?
 
Older Threads
Replies
1
Views
2,487
Replies
1
Views
2,134
Replies
84
Views
39,890
Recommended Threads
Replies
2
Views
2,373
Replies
3
Views
10,903
Replies
6
Views
4,762
Replies
6
Views
2,655

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top