Live Chat Software by NetForChoice
Knowledgebase
How-To: Install memcached on CentOS (WHM/cPanel)
Posted by Helpdesk System on 28 March 2016 06:50 PM

How-To: Install memcached on CentOS (WHM/cPanel)

Without wasting much time, Let us get started!

Follow these simple instructions for cPanel/WHM:

  • Step 1: Login into your WHM panel and using easyapache enable Memcache
  • Step 2: SSH into your server and fire this command yum install memcached.x86_64 php-pecl-memcache.x86_64
  • Step 3: Go to Software -> Module Installers -> PHP Pecl, Search for memcache and then install both memcache &memcached
  • Step 4: Restart apache once, Fire: service httpd restart
  • Step 5: Start memcache by firing this command: memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody (d = daemon, m = memory, u = user, l = IP to listen to, p = port)
  • Step 6: Check your memcached server is running successfully: ps -eaf | grep memcached
  • Then, install PHP memcache

·         # pecl install memcache

 

To manually installation of memcached use following steps:

Enable EPEL repository under RHEL/CentOS 6.3/5.8

The fastest and easiest way to install and enable EPEL repository using YUM. First, select the RPM that matches your Linux OS architecture from the provided links and install it using method shown in below. The EPEL repo will install all the required dependency packages for memcached. (Note : Fedora doesn’t required EPEL repo, because it is part of fedora project).

# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm


Install Memcached

Install Memcached program by using following command with YUM tool.

# yum install memcached

 

Sample Output
Loaded plugins: fastestmirror
Determining fastest mirrors
epel: kartolo.sby.datautama.net.id
Dependencies Resolved

=====================================================================================================
 Package			Arch				Version					Repository					Size
=====================================================================================================
Installing:			
memcached			i386				1.4.5-1.el5				epel						71 k

Transaction Summary
=====================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 71 k
Is this ok [y/N]: y
Downloading Packages:
memcached-1.4.5-1.el5.i386.rpm													|  71 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : memcached														          1/1

Installed:
  memcached.i386 0:1.4.5-1.el5

Complete!

 

Configure Memcached

Open the file called /etc/sysconfig/memcached with VI editor.

# vi /etc/sysconfig/memcached

Set or update parameters as follows, save the file and exit.

# Running on Port 11211
PORT="11211"

# Start as memcached daemon
USER="memcached"

# Set max simultaneous connections to 1024
MAXCONN="1024"

# Set Memory size to 2048 - 4GB(4096)
CACHESIZE="2048"

#Set server IP address
OPTIONS="-l 127.0.0.1"

Let’s discuss each of the above parameters in details.

  1. PORT : The port used by memcached to run.
  2. USER : The start-up daemon for memcached service.
  3. MAXCONN : The value used to set max simultaneous connections to 1024. For busy web servers you can increase to any number based on your requirements.
  4. CACHESIZE : Set cache size memory to 2048. For busy servers you can increase upto 4GB.
  5. OPTIONS : Set IP address of server, so that Apache or Nginx web servers can connect to it.

Start Memcached

Type the following commands to start and restart the Memcached daemon.

# chkconfig --levels 235 memcached on
# /etc/init.d/memcached start
# /etc/init.d/memcached restart

To stop and check status, use the following commands.

# /etc/init.d/memcached stop
# /etc/init.d/memcached status

Check the stats of the server using memcached-tool.

# memcached-tool 127.0.0.1 stats

Install Memcached PHP extension

Now, install PHP extension to work with Memcached daemon.

# yum install php-pecl-memcache

Install Memcached Perl Library

Install perl library for Memcached.

# yum install perl-Cache-Memcached

Install Memcached Python Library

Install python library for Memcached.

# yum install python-memcached


OR

We can install memcache from the source by following the steps below:

 

# wget http://pecl.php.net/get/memcache

# cd memcache-3.0.8

# phpize

Then, you can see something like this:

 # phpize

Configuring for:

PHP Api Version:         20100412

Zend Module Api No:      20100525

Zend Extension Api No:   220100525

 

Make sure that gcc and make library should be installed on server , If not then use following command.

# yum install make gcc

Next  configure memcache.

# ./configure

# make

#make install

Make sure memcache module is present in php.ini file. If not, add the memcache extension in php.ini file.

# echo "extension=memcache.so" >> /usr/local/lib/php.ini

Finally, restart Apache

# service httpd restart

Make sure memcached will be up even after a server reboot:

# chkconfig --levels 235 memcached on

How to check if memcache is installed or not?

 root@server [~]# php -m | grep memcache

memcache

That’s it!!!

 

Make sure that memcached  port 11211 should be open from iptables.

# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 11211 -j ACCEPT

# service iptables save

# service iptables restart

Verify Memcached

Use netstat command to verify Memcached is running.

# netstat -tulpn | grep :11211

tcp        0      0 127.0.0.1:11211             0.0.0.0:*                   LISTEN      20775/memcached
udp        0      0 127.0.0.1:11211             0.0.0.0:*                               20775/memcached


 

 

(1 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
Help Desk Support from NetForChoice