If you have a dedicated server or a VPS with CentOS and wants to make the server performance much better than your current with your WordPress sites, then you might want to try to make use of the memcached feature of W3 Total Cache. Nah, you should not immediately go to settings of the plug-in for you can’t enable it yet until you install memcached on your server. So read on to find out on how to install memcached on CentOS and memcache PHP extension.
Memcached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load.
- Install MEMCACHED via yum. Make sure to enable rpmforge respository using the following command to let you use yum to install the latest version of memcached.For i386 / i686
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
Use yum to install memcached
yum -y install memcached
- After memcached is successfully installed, configure it. Use the following to edit the memcached configuration.
The following shows the sample configuration that you can modify based on your needs.
PORT="11211" #define on which port to urn USER="nobody" #same as apache user MAXCONN="1024" #maximum number of connections allowed CACHESIZE="64" #memory used for caching OPTIONS="-l 127.0.0.1" #use for any custom options
On the last line OPTIONS=”-l 127.0.0.1″ – this should be placed to make sure that memcached is only accessible via your server only and other external sites can’t access it for security reasons.
Save the configuration and you can start memcached via:
If you want to check if memcached is running or not, use the following command.
- Next thing you need to do is to install the PHP extension. You need to download the latest stable version of memcache via PECL (http://pecl.php.net/package/memcache). In my case I use memcache 2.2.6. The following commands download the said version and install the memcache extension.
cd /usr/local/src wget http://pecl.php.net/get/memcache-2.2.6.tgz tar zxvf memcache-2.2.6.tgz cd memcache-2.2.6 phpize ./configure make make install
After you execute these commands, memcache.so will be installed in PHP modules directory. The next step will be enabling it in php.ini.
To find out your php.ini location, execute following command
php -i | grep php.ini
You’ll see the following output:
Configuration File (php.ini) Path => /usr/local/lib Loaded Configuration File => /usr/local/lib/php.ini
After determining the PHP configuration file location, edit it using:
Then add the following in the configuration near other extension declarations.
extension = "memcache.so"
Save the file and restart httpd server.
If you want to check if memcache extension was loaded successfully in php, just execute following command.
php -i | grep memcache
You’ll see some message containing memcache messages.
- If everything goes well with these steps, you can now go to W3 Total Cache and configure Page Cache, Browser Cache, Minify Cache to use “Memcached” option instead of the “Disk: Basic” or “Disk: Enhanced” to enable memcache on your site.
Enjoy now the new great performance of your site using memcache.