How to set up Memcached on CentOS 6 and configure WordPress to use it
Server efficiency is all the time a precedence, as web site load velocity is important for a superb consumer expertise, in addition to search engine rankings. One of the crucial standard methods to extend web site efficiency is to make use of Memcached – a distributed caching system that runs and may cache objects in-memory, lowering the variety of database and API calls.
The rise in efficiency is primarily resulting from a lower in disk I/O, which is a serious bottleneck on most servers. Even for SSD-equipped machines, it is smart to make use of Memcached with a purpose to cut back the variety of disk writes, growing the lifespan of the drive. CPU utilization can also be considerably decrease when utilizing Memcached.
Memcached is supported by all main CMS, and when you have a considerable amount of RAM (4+ GB), it’s usually a good suggestion to put in it. On this tutorial, we are going to present you learn how to set up and configure Memcached on CentOS 6.x and arrange WordPress to make use of it.
Establishing the Memcached server
Initially, you’ll want root privileges to run many of the instructions. To make it easy, you’ll be able to elevate your standing through the use of the su command and getting into your root password.
Now, you’ll want to put in memcached – the bottom CentOS6 repository has an outdated model, which is why we’ll add the RPMForge repo and set up the memcached bundle from RPMForge-Extras. We’ll additionally want the PHP-PECL-Memcache and PHP-PECL-Memcached packages so as to have the ability to use Memcached with WordPress (the PHP modules may be put in on the similar time – just one is definitely used, relying on the plugin).
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum set up memcached php-pecl-memcache php-pecl-memcached –enablerepo=rpmforge-extras
You’ll then have to configure a couple of Memcached settings:
nano -w /and so on/sysconfig/memcached
The default 1211 port doesn’t must be modified. You possibly can set any consumer, normally “no person” works high-quality. You solely have to set it as “root” when you set a port decrease than 1024. The Cachesize is determined by how a lot RAM you’ve gotten obtainable – usually 512-1024 MB needs to be sufficient. You’ll solely want to extend the connections restrict and cache dimension when you hit the bounds on them. It can save you and exit nano utilizing CTRL-O and CTRL-X.
Set Memcached to run on boot and begin it:
chkconfig memcached on
/and so on/init.d/memcached begin
Verify the stats to see if Memcached is working:
echo stats | nc localhost 11211
If you happen to see the stats, Memcached is working correctly.
Establishing WordPress to make use of Memcached
Now we will proceed to arrange WordPress to make use of Memcached. There are a number of plugins that may use Memcached – for this instance we’ll use WP-FFPC, which is easy and works with out points.
Open your WordPress dashboard, go to “Plugins”, click on “Add New” and seek for “WP-FFPC”. Click on on “Set up” and enter your FTP credentials. Word: you’ll be able to all the time set up it the previous manner, by way of handbook FTP add – in that case, you’ll be able to obtain the plugin from right here: http://wordpress.org/plugins/wp-ffpc/
After activating the plugin, you’ll see a couple of errors – to finish the activation, you’ll first want so as to add ” outline(‘WP_CACHE’,true); ” to the wp-config.php file within the root listing of your WordPress set up:
You’ll additionally must go to the plugin’s settings web page and click on “Save Modifications”:
You possibly can take a look at the caching system by loading your web site as a non-logged in consumer, then working “echo stats | nc localhost 11211” within the command line to see the outcomes. You must see objects being added to the cache, in addition to their dimension:
You may as well see if Memcached works with PHP by making a easy PHP file with the next code and opening it within the browser:
<?php $mc = new Memcached(); $mc->addServer(“127.0.0.1”, 11211);
$end result = $mc->get(“test_key”);
if($end result) echo $end result; else echo “No information cached. Please refresh the web page”; $mc->set(“test_key”, “Take a look at information present in cache!”) or die (“Failed to avoid wasting information with Memcached”); ?>
That’s it – your server has Memcached put in and working, and WordPress is configured to make use of it!