Memcached Installation Guide on CentOS

by johnsmith

Memcached is a cache system that works by temporarily storing the data you usually use in RAM. Because memory read speed is always higher than file storage, the use of memcached makes your system speed up significantly.

Memcached operation model:

Memcached Installation Guide on CentOS

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

Install Memcached
– Install Remi repository with CentOS 5 (CentOS 7 and 6 do not need this step)

## Remi Dependency on CentOS 5
rpm -Uvh
rpm -Uvh

– Install Memcached package:

## CentOS 7 and 6
yum install memcached

## CentOS 5
yum --enablerepo=remi install memcached

Note that two memcache packages exist: memcache and memcached (with the d at the bottom), as well as two versions of the PHP Extensions Module, php-pecl-memcache and php-pecl-memcached. We will use the second version (with the letter d) because it is stable and supports more functions.

Configure Memcached
The most important parameter to keep in mind is CACHESIZE, MB and MAXCONN. For example, underneath you use 128MB to cache (default 64MB). OPTIONS configures security only for local connect to port 11211.

# nano /etc/sysconfig/memcached
OPTIONS="-l -U 0"

Starts Memcached

chkconfig memcached on
service memcached start

To track the memcached status, you may be able to use phpMemcachedAdmin to view it right in your browser. PHPMemcachedAdmin is just downloadable, should be installed in the management directory of HocVPS Script for security. Specifically, I will install in the directory /home/

cd /home/
tar -xvzf 1.3.0.tar.gz
mv phpmemcachedadmin-1.3.0 memcached && chmod -R 777 memcached && chown -R nginx:nginx memcached
rm -f 1.3.0.tar.gz

Now you can access PHPMemcachedAdmin via domain:port/memcached/

Note: At the first time you will see the message “Error: Configuration file or folder is missing, please fix this error and try again”. You need to select Editing Configuration then Save Live Configuration to finish.
Install Memcache and Memcached PHP Module:
For Memcached to work with PHP, we need to install the PHP module.

PHP 5.5
yum --enablerepo=remi,remi-php55 install php-pecl-memcached php-pecl-memcache
PHP 5.6
yum --enablerepo=remi,remi-php56 install php-pecl-memcached php-pecl-memcache
PHP 7.0
yum --enablerepo=remi,remi-php70 install php-pecl-memcached php-pecl-memcache
PHP 7.1
yum --enablerepo=remi,remi-php71 install php-pecl-memcached php-pecl-memcache
Then restart PHP and web server
service php-fpm restart
service nginx restart

Open the Memcached port (11211) on the Iptables Firewall.
In case you use a separate server to run Memcached, you need to open port 11211 on the server cache.

Use the following command:

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
Restart Iptables Firewall
service iptables restart

Install Memcached as Session Handler

You can configure PHP to use Memcached as a session handler, instead of using files, to improve the performance of your system. Of course this should only be done with source code that uses multiple sessions, no need for WordPress.

Open file php.ini
nano /etc/php.ini
Find [Session], replace session.save_handler = files by:
session.save_handler = memcached
session.save_path = ""
Press Ctrl+O to save file, Ctrl+X to close editor.

If using phpMyAdmin, you need to customize the application’s session storage mechanism. Edit file of phpMyAdmin:

nano /home/
_Uncomment (remove //) line: //ini_set('session.save_handler', 'files');
_Add line : ini_set('session.save_path', '/tmp');
End, restart PHP again:
service php-fpm restart

Install Memcached works with WordPress.

For Memcached to work with WordPress you need to use the W3 Total Cache plugin.

In the plugin settings section, select the page cache method Memcached for the Page Cache, Database Cache, and Object Cache modules.

Now, enjoy the speed of Memcache.

Remove Memcached

If you do not use anymore and want to completely remove Memcached from the server, run the following command:

yum remove memcached php-pecl-memcached php-pecl-memcache
service php-fpm restart
service nginx restart
Good luck!

Related Posts


M.Muzammil 11 April, 2019 - 10:57 am

Amazing article Softweb Tuts

Sankar 7 December, 2019 - 6:40 pm

Great Article. Thank you for sharing! Really an awesome post for every one.

IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

JavaScript Training in Chennai

JavaScript Training in Chennai

Victoria 30 December, 2019 - 8:43 am

Finding a proper guide on CentOS is not easy, nice work !

sameer 10 April, 2021 - 10:02 am

The content is utmost interesting! I have completely enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great, and your efforts are outstanding! VPS

Mk Service 23 August, 2021 - 10:32 am

If you are working on a tight budget, there are several ways for you to get affordable business web hosting. Many people assume that once they get cheap hosting, they will have to deal with poor quality services. This is not always the case however.

justin 29 September, 2021 - 3:31 pm

Web hosting determines the functionality of your website and the kind of user experience you offer your visitors. Your hosting plan ought to be reliable and should be up round the clock, but this also relies on the web host you choose and the hosting plan you choose for your business. To ensure that you end up with the best plan, there are aspects that you should consider and make sure are in place. A reliable plan is very important, especially for business websites because the last thing you want to do is chase away valuable visits. Here are a few things to think about and check when searching for a hosting plan.

Sobat Berbagi 18 October, 2022 - 1:35 am

Artikel yang bagus, kalian dapat membaca artikel website seputar teknologi lainnya melalui laman ini TentangBerbagi dan kalian baca artikel game melalui artikel ini Point Blank


Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.