dot Become a Redis expert.

See what's new in Redis University

Turbo Boost WordPress with a Secure Memcached Plugin

Recently we released the Memcached Cloud Plugin for WordPress, implementing the WordPress Object Cache. The plugin is based on the PECL Memcached extension (note the ending ‘d’), working against the libmemcached library, ensuring a better and efficient performance as well as advanced features on top of the core memcached functions, such as multi set and get methods, ‘by key’ functions and many more- all are documented on php.net. We basically extended the wordpress-memcached-backend, so credits and many thanks goes to Zack Tollman.

As the PECL Memcached extension supports secured connection to Memcached servers using SASL authentication mechanism since version 2.2.0, working against a libmemcached built with SASL enabled, we wanted to provide a simple solution for WordPress users which their site is deployed in untrusted networks, and are requiring secured connection to their Memcached servers, or would like to exercise a bit more control over the clients connecting. Our Memcached Cloud service is of course allowing its users to configure their buckets with SASL effortlessly, providing a perfect and secured backend for the Memcached Cloud Plugin.

If you went over the installation section of the plugin, as we encourage you to do, you probably noticed that installing the plugin involves building libmemcached with SASL enabled and then installing the PECL Memcached extension, ver. 2.2.0, against the previously installed libmemcached library.

This process can be a bit non-trivial for the average user, and one solution can be taking advantage of the Heroku platform. Heroku’s PHP environment supports third-party extensions, that can be enabled through the composer.json file. Memcached; built against a version of libmemcached with SASL support, is supported as third-party extension. The Memcached Cloud Plugin natively supports Heroku’s Memcached Cloud configuration.

Below we’ll demonstrate an easy and straightforward method of deploying a WordPress application to Heroku with Memcached Cloud Plugin for WordPress and Memcached Cloud add-on for Heroku, as a backend:

Step 1 – Download

Start by downloading WordPress:

curl -sS http://wordpress.org/latest.zip > wordpress.zip
unzip wordpress.zip
rm wordpress.zip
mv wordpress/wp-config-sample.php wordpress/wp-config.php

Next, download the Memcached Cloud WordPress plugin:

curl -sS http://downloads.wordpress.org/plugin/memcached-cloud.zip > memcached-cloud.zip
unzip memcached-cloud.zip 
rm memcached-cloud.zip
mv memcached-cloud/object-cache.php wordpress/wp-content/object-cache.php

Step 2 – Configure

Create the file wordpress/Procfile with the following contents:

web: vendor/bin/heroku-php-nginx

Next, create the file wordpress/composer.json with the following contents:

{
    "require": {
        "ext-memcached": "*"        
    }
}

Lastly, edit your wordpress/wp-config.php file and set your database’s parameters.

Step 3 – Deploy

Initialize your git repository:

cd wordpress
git init
git add .
git commit -m "initial commit”

Next, create the Heroku app and add the Memcached Cloud add-on to it:

heroku create
heroku addons:add memcachedcloud

Note: this would also be a good time to add the database add-on to your app.

Finally, deploy the app:

git push heroku master

That’s all there is to it! Your WordPress is now deployed to Heroku and will use a secure connection to Memcached Cloud for that extra performance boost. I’d love to get your feedback on the plugin so please give your rating to it at the WordPress plugin page and discuss it at the plugin’s support forum. Happy blogging!