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:
- Install PHP and required packages:
sudo yum install -y php php-pear php-devel
- Download the latest
php-memcache
release from PECL repository.
pecl download memcache
- 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
- Edit
php.ini
and addextension=memcache.so
sudo vi /etc/php.ini
- Restart
PHP-FPM
service.
sudo systemctl restart php-fpm
- Confirm if the extension is loaded properly by running
php -m
or checking the output ofphpinfo()
. You should see the package modulememcache
listed.
<?php
phpinfo();
?>
- 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.
Congrats! Now the WordPress is ready to use Memcached!