AWS

How to Install Memcached on Amazon Linux 2023 AMI

Xavier
May 5, 2024
2 min read
WordPressElastiCacheMemcachedAmazon Linux 2023 AMIWordpress on AWS
Step by Step Guide How to Install Memcached on Amazon Linux 2023 AMI

The Amazon Linux 2023 AMI is an image maintained by AWS. I found it interesting to use it to install my WordPress solution to leverage the power of ElastiCache using Memcached.

I first tried the WordPress AMI Certified by Bitnami, but unfortunately I wasn't able to install it successful. I followed the guides to install Memcached into it, but WordPress never recognised it. If anyone has done this successfully, please feel free to drop a comment or message.

Now let's discuss how to install Memcached on Amazon Linux 2023.

To be able to use Memcached in Wordpress, the php-memcache extension needs to be installed, as it is not included by default on this AMI.

To install php-memcache on an Amazon EC2 instance running Amazon Linux 2023 AMI, follow these steps:

  1. Install PHP and required packages:
sudo yum install -y php php-pear php-devel
  1. Download the latest php-memcache release from PECL repository.
pecl download memcache
  1. In the previous step you downloaded the source, proceed to extract and compile the php-memcache package.
tar -xzf memcache-8.2.tgz
cd memcache-8.2
phpize
./configure
make
make install
  1. Edit php.ini and add extension=memcache.so
sudo vi /etc/php.ini
  1. Restart PHP-FPM service.
sudo systemctl restart php-fpm
  1. Confirm if the extension is loaded properly by running php -m or checking the output of phpinfo(). You should see the package module memcache listed.
<?php
	phpinfo();
?>
  1. Login to your Wordpress portal. In my case I use the W3 Total Cache plugin to configure Memcached.

Note: If you're interested in how to install the plugin, check this post.

Then, go to Performance > General Settings > Database Cache and click on the dropbox Database Cache Method. You’ll see Memcached ready to select.

WordPress W3 Total Cache plugin for Memcached

Congrats! Now the WordPress is ready to use Memcached!


Cloud & DevOps 101

Subscribe to my newsletter and get the most out of the Cloud & DevOps, with personal tips, resources, and much more.

Oops! There was an error sending the email, please try again.

Awesome! Now check your inbox and click the link to confirm your subscription.