Search Engine Optimization (SEO) is neither mystical nor magical. It's a blend of guidelines and…
I use the Memcached Redux plugin on all of the servers and WordPress installs that I manage. I want to share the proper way to get your WordPress and Debian server setup to utilize Memcached. This guide will also set your server up correct for a server with multiple WordPress instances.
What You’ll Need
- Self-hosted WordPress Instance
- Memcached Redux Plugin installed (not activated)
- Memcached
- PHP5 Memcached Module
Prerequisites
- WordPress Self-Hosted
- Debian Server OS (Example: Ubuntu)
Installation
-
Download the Memcached Redux plugin and put it in your /wp-content/plugins/ directory
-
Don’t Activate the plugin (never activate the plugin)
- copy the object-cache.php file from /wp-content/plugins/memcached-redux/ directory to the wp-content directory.
- Open your wp-config.php file for editing
- In the “Authentication Unique Keys and Salts” section place the following line below the $table_prefix definition (required for multi-install servers):
define('WP_CACHE_KEY_SALT', md5( DB_NAME . $table_prefix . __FILE__ ) );
- Save the file
- From your server’s command line install memcached
sudo apt-get install memcached
- From your server’s command line install php5-memcached
If you have php5:
sudo apt-get install php5-memcached
If you have php7:
sudo apt-get install php-memcached
- Restart apache
sudo service apache2 restart
F.A.Q.
Why shouldn’t I activate the Memcached Redux plugin?
The plugin serves as a placeholder for the object-cache.php file. It can also serve as a way for you to know if there are updates in the future. If you do activate it you’ll receive the following PHP Fatal error and your site and/or admin will display a White Screen of Death (WSOD).
PHP Fatal error: Cannot redeclare wp_cache_add()
This is because when a plugin is activated WordPress will execute the code contained in it’s main php file. Copying the object-cache.php to the wp-content/ directory is all that’s needed to make the plugin work.
Why do I need to add the WP_CACHE_KEY_SALT definition in wp-config.php?
This step is good for anyone to do, but is highly recommended for servers that host multiple WordPress installations that are using memcached.
An example of what could happen if you don’t take the step on a multi-install server is any blog using a common database prefix (default is wp_) could take on portions of other sites using the same prefix.
I haven’t done extensive testing, but it appears that sites that use different database prefixes are likely ok to exclude this extra definition, but better to be safe than sorry.
Why did you write this guide?
I’m neither the plugin author or a contributing developer on the memcached project, but I am an enthusiastic user. That said, the information above was gleaned from multiple sources and I couldn’t find a comprehensive guide on how to fully install and use the Memcached Redux plugin.
Disclaimer
Purrly Digital LLC cannot be held responsible for the functionality of this code. Please make sure you test it on a development site before adding the code to your production website. There is no support available for this (and other) code snippet(s) posted on this website. If you’d like Purrly Digital to do custom development to help with your custom implementation please send a contact request.
Thank you. I was able to enable memcached with aws elasticache using your blog.
But wp-admin login failed. I had to remove object-cache.php to restore the login.
Ramanm,
Sorry to hear that. I haven’t attempted this code in a few years. Did you happen to grab the errors that were happening? This post is on my schedule for review.
I’m keen to speed up wordpress for logged in users. (Page caching is all very nice but only when it’s turned on which is not the case for logged in users so it’s useless).
But here’s the question. Supposing a DB query (select x, y, z, from xxxx) goes into the object cache. Then some other user (perhaps an admin) causes an update to that table. Now a third user comes along and needs the same info. If that info comes from the object cache it’s going to be old data right? If I am wrong let me know. (I just want to save my self some time since I don’t want to have that “old data” problem on my site).
Thank you for the great post. Please tell me, can I delete the plugin after copying the object cache php file to wp content. Also, how can I test to make sure that memcached is actually working ?