Installing Memcached on CentOS and DirectAdmin for WordPress

by Jeffrey van Rossum

This article will go through the steps to get Memcached installed on a Centos (7 or 8) server with DirectAdmin.

I needed to install Memcached to make use of object caching in WordPress on a VPS. The VPS was hosting one website with at the time storing the object cache on disk. Using Memcached would be more performand.

Make sure to run most of the commands as root.

Install memcached

Run the following to install Memcached.

yum install memcached
yum install memcached-devel
yum install libmemcached-devel
yum install libmemcached

If you would like to modify the configuration of memcached, you can find the config file at the following location:

nano /etc/sysconfig/memcached

For security tips check out this article at DigitalOcean.

Install PHP extension

I like to use a custom PHP extension script for DirectAdmin. This makes it easy to install extensions for PHP on DirectAdmin. Follow the steps in that article listed under "Let's start".

Once you can run the php-extension.sh script, run the following to install the memcached extension:

./php-extension.sh install memcached

Then check if the extension has been installed by running:

./php-extension.sh status memcached

Restart your server for the extension to be recognized. You might have to restart memcached after your server has restarted.

systemctl restart memcached

Using memcached with WordPress

To make WordPress use Memcached, consider installing the Memcached Redux plugin. Note that the installation of this plugin is different then how you'd regularly install plugins.

Instead of activating the plugin, place the object-cache.php file inside your wp-content folder.

Did you like this post?

If you sign up for my newsletter, I can keep you up to date on more posts like this when they are published.